openapi-generators / openapi-python-client

Generate modern Python clients from OpenAPI
MIT License
1.25k stars 193 forks source link

field required (type=value_error.missing) #681

Closed cristiang777 closed 2 days ago

cristiang777 commented 1 year ago

Hi, I'm sure this is related to my project, not to the openapi-python-client, but needed some help. When running the app, I get the following errors:

Error(s) encountered while generating, client was not created

Failed to parse OpenAPI document

50 validation errors for OpenAPI
paths -> /auth/login -> post -> requestBody -> content -> application/x-www-form-urlencoded -> schema -> $ref
  field required (type=value_error.missing)
paths -> /auth/login -> post -> requestBody -> content -> application/x-www-form-urlencoded -> schema -> properties -> user -> $ref
  field required (type=value_error.missing)
paths -> /auth/login -> post -> requestBody -> content -> application/x-www-form-urlencoded -> schema -> properties -> user -> required
  value is not a valid list (type=type_error.list)
paths -> /auth/login -> post -> requestBody -> content -> application/x-www-form-urlencoded -> schema -> properties -> password -> $ref
  field required (type=value_error.missing)
paths -> /auth/login -> post -> requestBody -> content -> application/x-www-form-urlencoded -> schema -> properties -> password -> required
....

And here's some of api.yaml file that I'm using:

paths:
  /auth/login:
    post:
      tags:
      - Auth
      summary: Authenticate with API
      description: Authenticate with API getting bearer token
      requestBody:
        description: Request values
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                user:
                  description: API user name
                  type: string
                  required: true
                password:
                  description: API password
                  type: string
                  required: true
            required:
              - user
              - password

Any thoughts on what's wrong?

kraktus commented 1 year ago

bump, encountering the same issue.

harrystuart commented 1 year ago

Did you ever find a fix?

kraktus commented 1 year ago

Unfortunately not

benedikt-bartscher commented 8 months ago

This just happened to me with the sentry openapi schema, which is openapi version v3.0.3. I tried to load the schema directly with openapi-pydantic (see here) which worked fine. It seems like openapi-python-client bundles its own version of openapi-pydantic which does not work with v3.0.3. I did a quick and dirty try to replace the included version (in openapi_python_client/schema/) with the latest upstream openapi-pydantic which needed some little adjustments but worked fine overall. @dbanty are there any special reasons for the vendored version?

dbanty commented 8 months ago

It needed a bunch of customizations to work the way I needed. It could be that the latest version works much better, but it'd take a lot of validation to be sure

joaonc commented 2 days ago

required needs to be at the same level as properties and in the example given, it's at the level of schema, which is wrong.

The required functionality is working just fine.

This ticket can be closed, imo.

dbanty commented 2 days ago

I think the real problem here is that the errors Pydantic gives are not very helpful. So a lot of people end up with the same error message as this issue. I agree that I don't think required is the problem, and we probably need new issues for other problems.