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

fix(oas3): fix getting initial values for request body in OpenAPI 3.x #9762

Merged
merged 5 commits into from
Mar 29, 2024

Conversation

glowcloud
Copy link
Contributor

Changes the behaviour from only getting initial values for the parameters that have examples or have type object to getting initial values for every parameter. Also fixes the issues of not getting examples and correct input in the form for anyOf and oneOf, and of not filling initial values if they are falsy. Changes based on findings documented in #9754.

Applies to request bodies with content type application/x-www-form-urlencoded and multipart/....

Before:
Screenshot 2024-03-28 at 10 43 12

After:
Screenshot 2024-03-28 at 10 44 58
Screenshot 2024-03-28 at 10 45 17

const oneOf = schema.get("oneOf")
const anyOf = schema.get("anyOf")

if (oneOf || anyOf) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could move handling these below this line

  let initialValue = fn.getSampleSchema(schema, false, {
    includeWriteOnly: true
  })

So that if the parent schema has an example, we would get the initial value from it. We would need to reassign the schema, type, format and description then.


const schemaWithoutKeywords = schema.filter((v, k) => k !== "oneOf"
&& k !== "anyOf"
&& k !== "$$ref"
Copy link
Contributor Author

@glowcloud glowcloud Mar 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think $$ref should be the exception when checking if we have properties other than anyOf or oneOf in the schema.

Not sure if there's a better way of doing this than filtering out these properties.

@glowcloud
Copy link
Contributor Author

I updated the code so that we won't be overwriting existing properties in the schema with the nested schema and created an issue for not getting nested schema properties: #9763

I'm wondering though, wouldn't this be solved by merging the nested schema with the parent schema?

@glowcloud glowcloud changed the title refactor(oas3): refactor getting initial values for request body in OpenAPI 3.x fix(oas3): fix getting initial values for request body in OpenAPI 3.x Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant