cancel
Showing results for 
Search instead for 
Did you mean: 

Codegen and inheritance

Highlighted
Frequent Visitor

Codegen and inheritance

I will start by saying I'm not sure how to even search for this, I tried but couldn't find a post like my problem. Currently I'm having some troubles with how to hanlde inheritance in swagger 3.0 and codegen on that swagger. The api this swagger is for uses alot of the same fields accross its different endpoints. To reduce the workload around updates to these fields I pulled all of the fields out into their own section in the schema. This has been fine for the documentation side but codegen is now generating models for each seperate field and getting really confused because of it. I have a couple of questions I'm wanting to ask here.

Is this the correct way to handle repeating fields? is there a better way while not requring updated to each location the field is used?
Assuming the answer to my first question isn't I'm doing everything wrong how can I reformat my swagger file to codegen only the actual models

openapi: 3.0.0
info:
  title: Test Service
  version: 0.4.0
paths:
  /example:
    parameters:
      - $ref: '#/components/parameters/X-Request-ID'
      - $ref: '#/components/parameters/X-Correlation-ID'
    put:
      tags:
        - example
      summary: Update | /example PUT
      description: needed to hide these
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/update'
      responses:
        '200':
          $ref: '#/components/responses/PutResponse'
components:
  schemas:
    update:
      type: object
      properties:
        clientId:
          $ref: '#/components/schemas/clientId'
        userId:
          $ref: '#/components/schemas/userId'
        deviceId:
          $ref: '#/components/schemas/deviceId'
        state:
          $ref: '#/components/schemas/state'
        name:
          $ref: '#/components/schemas/name'
      required:
        - clientId
        - userId
        - deviceId
    putResponse:
      type: object
      properties:
        clientId:
          $ref: '#/components/schemas/clientId'
        userId:
          $ref: '#/components/schemas/userId'
        deviceId:
          $ref: '#/components/schemas/deviceId'
        state:
          $ref: '#/components/schemas/state'
        name:
          $ref: '#/components/schemas/name'
        lastUpdated:
          $ref: '#/components/schemas/lastUpdated'
    X-Correlation-ID:
      description: needed to hide these
      example: 2438ac3c-37eb-4902-adef-ed16b4431030
      pattern: ^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$
      type: string
      format: uuid
    clientId:
      description: needed to hide these
      example: 900900
      pattern: ^[a-zA-Z0-9]{1,64}$
      type: string
    deviceId:
      description: needed to hide these
      example: 7363b8ae6b2247b99f5d56fc81102254
      pattern: ^[a-zA-Z0-9]{1, 32}$
      type: string
    userId:
      description: needed to hide these
      example: meoyyd8za8jdmwfm
      pattern: ^[a-zA-Z0-9]{1,64}$
      type: string
    state:
      type: string
      description: needed to hide these
        TRUSTED - Used to minimize friction for a user who has passed step-up authentication
        BANNED - Used to block access to an account for a specified device
      enum:
        - TRUSTED
        - BANNED
    name:
      type: string
      description: needed to hide these
      example: iPhone6sNina
      pattern: ^\w{1,255}$
    lastUpdated:
      type: string
      format: date-time
      description: needed to hide these
      example: 2018-02-22T01:02:03.123Z
      pattern: "yyyy-MM-dd'T'HH:mm:ss'Z'"
  parameters:
    X-Request-ID:
      description: needed to hide these
      name: X-Request-ID
      schema:
        $ref: '#/components/schemas/X-Correlation-ID'
      deprecated: true
      in: header
    X-Correlation-ID:
      description: needed to hide these
      name: X-Correlation-ID
      schema:
        $ref: '#/components/schemas/X-Correlation-ID'
      required: true
      in: header
    clientId:
      name: clientId
      description: needed to hide these
      schema:
        $ref: '#/components/schemas/clientId'
      required: true
      in: path
    deviceId:
      name: deviceId
      description: needed to hide these
      schema:
        $ref: '#/components/schemas/deviceId'
      required: true
      in: path
    userId:
      name: userId
      description: needed to hide these
      schema:
        $ref: '#/components/schemas/userId'
      required: true
      in: path
  responses:
    PutResponse:
      description: needed to hide these
      headers:
        X-Correlation-ID:
          schema:
            $ref: '#/components/schemas/X-Correlation-ID'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/putResponse'


This ends up generating swagger filed with models for each field like userId, deviceId, and so on. What I really want is the update and postRepsonse models.