Inline type declaration with Type Expression


#1

Hi all

For example, I have this:

types:
  City:
    properties:
      name: string

/cities:
  post:
    body:
      application/json:
        type: City

POST method used for new entity creation.

I want implement GET method for resource “cities”, which should return “City” collection, but all instances in its response MUST have IDs (for example, “cityId” field).

This is not valid:

/cities:
  get:
    responses:
      200:
        body:
          application/json:
            type: City[]
            properties:
              cityId:
                type: number

Because of

“You can declare inline/anonymous types everywhere a type can be referenced except in a Type Expression.”

I do not want to add “cityId” field into my “City” type, because it not needed in the POST (creation) request.
How can I solve this problem?


#2

Have you tried:

types:
  City:
    properties:
      name: string

/cities:
  post:
    body:
      application/json:
        type: array
        items:
          type: City
          properties:
            cityId: number

#3

I need cityId’s to be returned in GET Response, and you are talkin about POST Request :slight_smile: :wink:


#4

Sorry my mistake :slight_smile: Although, it does not change anything. You can simply copy and paste the code after application/json.

/cities:
  get:
    responses:
      200:
        body:
          application/json:
            type: array
            items:
              type: City
              properties:
                cityId: number

#5

Christian, thanks, it’s works!)