Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go (client) is not able to generate code that compiles for allOf #18385

Closed
rikotsev opened this issue Apr 15, 2024 · 1 comment · Fixed by #18390
Closed

Go (client) is not able to generate code that compiles for allOf #18385

rikotsev opened this issue Apr 15, 2024 · 1 comment · Fixed by #18390

Comments

@rikotsev
Copy link
Contributor

Is your feature request related to a problem? Please describe.

I have a schema in which an object is constructed from allOf with multiple refs, one of the refs itself has a discriminator field that points to the object.

Currently, the code cannot compile because the model_simple.mustache uses allVars in the helper (constructor) func while the struct has fields only coming from vars

Describe the solution you'd like

I would like the resulting code to have all the fields needed.

Describe alternatives you've considered

One alternative would be to build the schema as:

    FinalItem:
      type: object
      allOf:
        - allOf:
           - $ref: '#/components/schemas/BaseItem'
        - allOf:
            - $ref: '#/components/schemas/AdditionalData'

Additional context

This is an example schema for this:

openapi: 3.0.0
info:
  title: Test
  version: 1.0.0
paths: {}
components:
  schemas:
    FinalItem:
      type: object
      allOf:
        - $ref: '#/components/schemas/BaseItem'
        - $ref: '#/components/schemas/AdditionalData'
    BaseItem:
      type: object
      properties:
        title:
          type: string
        type:
          type: string
          enum:
            - FINAL
          example: FINAL
      discriminator:
        propertyName: type
        mapping:
          FINAL: '#/components/schemas/FinalItem'
      required:
        - title
        - type
    AdditionalData:
      type: object
      properties:
        prop1:
          type: string
        quantity:
          type: integer
          format: int32
          example: 1
          minimum: 1
        unitPrice:
          type: number
          format: double
          example: 9.99
          minimum: 0.0
        totalPrice:
          type: number
          format: double
          example: 9.99
          minimum: 0.0
      required:
        - sku
        - quantity
        - unitPrice
        - totalPrice
@rikotsev
Copy link
Contributor Author

I've added an example proposal:

#18390

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant