-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Example.externalValue
is not displayed
#5433
Comments
I don't know if this is the appropriate issue, but instead of binary image, I simply want external JSON to display. Is this already planned?
I build my self a quick hack, that works for me for now |
Same for me, would like to embed external |
@shockey Thank you for opening this issue! Do you know an approx. ETA for this? |
I have the same problem. I prefer to keep my examples in external .json files (same with models) so as not to clutter the spec itself too much. Any idea where this is in the priority stack please? |
Same here. externalValue does not display the pointed json |
Same here. |
Echoing this issue. Would be helpful to finally have |
The documentation says that there is possible to use |
Has someone found a way to bypass this issue and somehow use |
Anything that can be done to get this on the roadmap? |
Any workaround for this issue? Please share the details when we should expect the fix. |
Can we get this fixed please? You have done a great job on introducing multiple example values for the multiple ways that an API endpoint can be called - now please let us also use them in your UI! |
Hallo, swagger team @fehguy could you prioritise this task? External examples are crucial, I mean SUPER IMPORTANT, for spreading Single Source of Truth principle on mocking objects reusable across testing frameworks, and especially, for staging environments across platforms. |
@tim-lai I think this is only partially a swagger-ui issue! Else ways I will implement some resolver that will fetch the raw value hosted behind the externalValue url. |
@mathis-m , I am facing the same issue. Is this issue resolved? |
Workaround with wrapComponents Sample openapi: 3.0.1
info:
title: Swagger Petstore
description: 'This is a sample server Petstore server'
version: 1.0.0
servers:
- url: https://petstore.swagger.io/v2
- url: http://petstore.swagger.io/v2
paths:
/router/rest:
get:
summary: test
operationId: test
responses:
'200':
content:
application/json:
schema:
type: object
examples:
success:
summary: JSON example
value: Loading...
externalValue: 'example/test.json'
application/xml:
schema:
type: object
xml:
name: xml
examples:
success:
summary: XML example
value: Loading...
externalValue: 'example/test.xml' Add custom plugin to // Examples map
const examples = {};
// Custom plugin for logic that happens before the response element is created
const CustomPlugin = () => {
return {
wrapComponents: {
response: (Original, { React, oas3Actions, oas3Selectors }) => (props) => {
const contentType = oas3Selectors.responseContentType(props.path, props.method)
const externalValue = props.response.getIn(['content', contentType, 'examples', props.activeExamplesKey, 'externalValue'])
// Check if externalValue field exists
if (externalValue) {
// Check if examples map already contains externalValue key
if (examples[externalValue]) {
// Set example value directly from examples map
props.response = props.response.setIn(['content', contentType, 'examples', props.activeExamplesKey, 'value'], examples[externalValue])
} else {
// Download external file
fetch(externalValue)
.then(res => res.text())
.then(data => {
// Put downloaded file content into the examples map
examples[externalValue] = data
// Simulate select another example action
oas3Actions.setActiveExamplesMember({
"name": 'fake',
"pathMethod": [props.path, props.method],
"contextType": "responses",
"contextName": props.code
})
// Reselect this example
oas3Actions.setActiveExamplesMember({
"name": props.activeExamplesKey,
"pathMethod": [props.path, props.method],
"contextType": "responses",
"contextName": props.code
})
})
.catch(e => console.error(e))
}
}
return React.createElement(Original, props)
}
}
}
}
window.onload = function() {
const ui = SwaggerUIBundle({
url: 'openapi.yaml',
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl,
// Add custom plugin
CustomPlugin
],
layout: "StandaloneLayout"
});
window.ui = ui;
}; |
I guess this issue also applies to having xml documents as |
I am facing the same issue. The workaround helps to make it work. But can anyone provide me the permanent fix on this. |
Thanks for this fix! Do you have any suggestions on how to get this working for the request body as well. I want to have an example with an external JSON File within the Request Body.
|
Push. |
If you have time have a look at swagger-api/swagger-js#1978 and finish it up. Currently I have no time to work on it. |
Hello Team, I am working on @mathis-m @arman-sydikov If you get a chance please provide some work-around. Thanks a lot in advance. |
In case it helps somebody else...I'm using
|
I dont have any experience with JS and that's not the point i was trying to convey to be honest. |
It is literally all there, in my initial pr at swagger-api/swagger-js#2013 It is just missing the base64 part and some tests. |
Any news ? |
Hi @ben12, This is actually already supported in SwaggerUI@5 and OpenAPI 3.1.0 definitions. openapi: 3.1.0
info:
title: Swagger Petstore
description: 'This is a sample server Petstore server'
version: 1.0.0
servers:
- url: https://petstore.swagger.io/v2
- url: http://petstore.swagger.io/v2
paths:
/router/rest:
get:
summary: test
operationId: test
responses:
'200':
description: response
content:
application/json:
schema:
type: object
examples:
success:
summary: JSON example
externalValue: https://gist.githubusercontent.com/char0n/5c35aee4fd95a23b18f6ed76d51ce83f/raw/0014ab1e8882ffbe285465ded4c18b4b745aecc4/test.yaml URIs with Related to OpenAPI 3.0.x support, work for this has been done already by @mathis-m in swagger-api/swagger-js#2013, but in long term we want OpenAPI 3.0.x resolution to be facilitated by ApiDOM (same as for OpenAPI 3.1.0) and not by old legacy specmap mechanism. |
Thanks, it work. My mistake was the OpenApi version (3.0.3 instead of 3.1.0). So this issue may be closed ? |
I'm just glad that you can use this feature for your OpenAPI 3.1.0 definitions now.
Not really, as we're still missing this feature for OpenAPI 3.0.x. We'll introduce ApiDOM facilitated resolution for OpenAPI 3.0.x as an opt-in behavior in SwaggerClient and SwaggerUI subsequently. If/When we have this, we can close this issue. |
Hi @char0n, Thanks for your comment, By your comment we are able to use OpenAPI 31 to show the external Value. But we still have some questions. env: |
Any updates around this? I can't believe this issue has several years open, but i have hope in you fixing it some day. |
Example Swagger/OpenAPI definition
Current behavior
Expected behavior
I should be able to use the externally-referenced image as an example value for my endpoint (provided that Swagger UI is able to reach the resource).
Additional context or thoughts
#5427.
The text was updated successfully, but these errors were encountered: