oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

allOf with references doesn't respect import mappings

Open serejja opened this issue 3 years ago • 1 comments

When upgrading to 1.11.0, it seems that allOf with external file reference doesn't work and generates broken code:

common.yml

genericResponse:
      type: object
      required:
        - message
        - requestData
      properties:
        message:
          type: string
        requestData:
          $ref: '#/components/schemas/requestData'

requestData:
      type: object
      required:
        - field1
        - field2
      properties:
        field1:
          description: field1
          type: string
        field2:
          description: field2
          type: string

api.yml

someApiResponse:
      allOf:
        - $ref: 'common.yml#/components/schemas/genericResponse'
        - type: object
          required:
            - data
          properties:
            data:
              type: object
              required:
                - field1
              properties:
                field1:
                  type: string

import mapping between common and API is set up correctly, and I see it working for other fields that don't use allOf. What doesn't work though, is the reference to requestData in someApiResponse, because instead of being an *externalRef0.RequestData, it's being generated as just RequestData, which obviously doesn't work.

In this particular case, I have a someApiResponse, that references genericResponse, that references requestData. It seems that the code generated for genericResponse doesn't "know" the context and generates standard code without any external references

serejja avatar Jun 17 '22 15:06 serejja

Any update on this one? I came across the same issue.

macpoint avatar Jun 29 '22 08:06 macpoint