RAML: Nested Schemas

后端 未结 3 1899
眼角桃花
眼角桃花 2021-02-06 14:12

1) When writing RAML, can I use nesting in my schema definition?

For example:

schemas:
  - DNSResponse: |
      {
        \"type\": \"object\",
        \         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-06 14:51

    Since your question is not 100% requiring JSON, I will add this in the answers...

    With the release of the RAML 1.0 specifications, you can use types, which allows you to do just that (in what I consider slightly cleaner).

    Here is the reference link : http://docs.raml.org/specs/1.0/#raml-10-spec-types

    RAML 1.0 introduces the notion of data types, which provide a concise and powerful way to describe the data in your API. The data can be in a URI parameter (base or resource URI), a query parameter, a request or response header, or of course a request or response body. Some types are built in, while custom types may be defined by extending (inheriting from) the built-in types. In any place where the API expects data, a built-in type may be used to describe the data, or a type may be extended inline to describe that data. CustomSecurityScheme types may also be named and then used like any built-in type.

    And for those that want less text and more examples (taken from RAML documentation) :

    #%RAML 1.0 
    title: API with Types
    types:
      User:
        type: object
        properties:
          firstname: string
          lastname:  string
          age:       number
    /users/{id}:
      get:
        responses:
          200:
            body:
              application/json:
                type: User
    

提交回复
热议问题