mike-oakley / openapi-pydantic

Pydantic OpenAPI schema implementation
Other
55 stars 9 forks source link

Correct Header objects #22

Closed hathawsh closed 9 months ago

hathawsh commented 1 year ago

This PR removes the "name" and "in" fields from Header objects. The OpenAPI spec says they must not be present:

https://spec.openapis.org/oas/latest.html#header-object

Also made two fields optional that were causing validation failures: allowReserved and allowEmptyValue.

hathawsh commented 1 year ago

Hey @mike-oakley , what are your thoughts on this PR?

mike-oakley commented 1 year ago

Sorry - missed this one before!

This PR removes the "name" and "in" fields from Header objects.

Makes sense - I guess this is breaking but simple transition is to switch to 'Parameter' objects if using 'Header' in the request specs instead of the shared models.

Also made two fields optional that were causing validation failures: allowReserved and allowEmptyValue.

Can you highlight why this is necessary? Seems that by making them optional we're deviating from the defaults in the OpenAPI spec?

hathawsh commented 1 year ago

I used openapi-spec-validator to validate a generated OpenAPI spec; those extra fields caused the validation to fail. I think what I should do is add openapi-spec-validator to this project as a testing dependency, then add test cases that reveal validation failures as they're discovered. Then we'll be able to discuss the validation failures more easily.

mike-oakley commented 1 year ago

👍🏼 sounds good to me

manycoding commented 10 months ago

Any updates on this one? This became a blocking issue because of allowEmptyValue

hathawsh commented 9 months ago

@manycoding: I learned that if I add exclude_defaults=True to the model_dump call, the allowEmptyValue issue goes away. The generated JSON no longer contains the invalid key.

hathawsh commented 9 months ago

@mike-oakley This PR now adds the openapi-spec-validator dependency and adds tests that verify we're generating spec-compliant JSON. I added some cases that previously failed validation, particularly a header spec.

mike-oakley commented 9 months ago

LGTM - thanks @hathawsh!

mike-oakley commented 9 months ago

Released to PyPI in version 0.4.0 🎉