-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[HTTP/OAS] Support specifying content types #181697
[HTTP/OAS] Support specifying content types #181697
Conversation
…content type. Also fixed a bug...
@@ -62,6 +62,7 @@ const getRouterDefaults = () => ({ | |||
200: { | |||
body: schema.string({ maxLength: 10, minLength: 1 }), | |||
}, | |||
unsafe: { body: true }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added to make the tests more representative
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored this file to make things a bit more maintainable
} else if ((schema.type as string) === 'stream') { | ||
mutations.processStream(schema); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible that a response body is a stream, in this case we just map it to object
which is similar to "any" in OAS. Not sure there is good way to represent this at present.
/ci |
/ci |
Pinging @elastic/kibana-core (Team:Core) |
packages/core/http/core-http-server/src/router/route_validator.ts
Outdated
Show resolved
Hide resolved
...bn-router-to-openapispec/src/oas_converter/kbn_config_schema/post_process_mutations/index.ts
Outdated
Show resolved
Hide resolved
return route.handlers.reduce<OpenAPIV3.ResponsesObject>((acc, handler) => { | ||
const schemas = extractValidationSchemaFromVersionedHandler(handler); | ||
if (!schemas?.response) return acc; | ||
const { unsafe, ...responses } = schemas.response; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fix/change that is obscured due to refactor. Ensure that we are looping over status code-like key values only.
const fullConfig = getResponseValidation(route.validationSchemas); | ||
|
||
if (fullConfig) { | ||
const { unsafe, ...validationSchemas } = fullConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fix/change that is obscured due to refactor. Ensure that we are looping over status code-like key values only.
...bn-router-to-openapispec/src/oas_converter/kbn_config_schema/post_process_mutations/index.ts
Outdated
Show resolved
Hide resolved
💚 Build Succeeded
Metrics [docs]
History
To update your PR or re-run it, just comment with: cc @jloleysens |
Summary
Related to #180056
Adds the ability to specify a content type for the request / response of an API. The current approach is to use the
options.accepts
value already present on the route but to also add the ability to specify a content type per response, otherwise fallback toapplication/json
.Notes
generate_oas.ts
script to be more maintainable (apologies for the noise)