openapi-processor/openapi-processor-spring

Uncompilable java code when schema having properties

beeondev opened this issue · 3 comments

Hi,

in the given my-test-case.ZIP , the openapi.yaml is valid, and the processor generates target files wiyhout complaining, but thoses files just not compiles.

The described endpoint (from YAML point of view) is a function expected a JSON body argument composed of 3 elements

  • string
  • string
  • either an array of enum values or a simple string

But the processor does not generates anything in the model : class EndpointIdPostRequestBody not exists.

Best regards.

Workaround seems to help the processor by providing explicit additional schema.
Typically avoid to have raw inlined schema withing method, but rather declare explicit "component/schema/**" types.

Applying this rules (openapi.ZIP ), and the model compiles.

hauner commented

The processor generates only classes that are used in the api. It probably does not detect that the class is needed.

I guess this a bug. Looking at it.

hauner commented

so, it is not what I thought. What causes the issue is that the processor depends on the type attribute. Without it, it doesn't understand that the schema is an object and walks into the wrong code path.

adding type: object fixes the issue.

      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              # adding this repairs it
              type: object

Not sure If I can detect it without the type. I think type comes from JSON schema validation and is not required. Hmm, have to think about this :-)