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

Support custom media type #460

Open
achifal opened this issue Jul 21, 2021 · 6 comments
Open

Support custom media type #460

achifal opened this issue Jul 21, 2021 · 6 comments

Comments

@achifal
Copy link

achifal commented Jul 21, 2021

Hi! I have the following code

@GET
@Operation(
        ...
        responses = {
                @ApiResponse(
                        responseCode = "200",
                        content = @Content(
                                examples = {
                                        @ExampleObject(
                                                name = "Some name",
                                                value = "Some Value"
                                        )
                                }
                        ))
        })
@Produces("customMediaType")
public A fetchFont() {
    ... 
}

with this code the following piece of documentation will appear in swagger.json

"200" : {
    "content" : {
        "customMediaType" : {
            "examples" : {
                "Some name" : {
                    "value" :  "Some value"
                }
            }
        }
    }
}

However, when converting json to md using widdershins, this section is not displayed. This is due to the custom media type.
Thanks in advance for any effort on this issue!

@MikeRalphson
Copy link
Contributor

Is customMediaType a placeholder or the actual value you are using? According to the spec, the keys within a content object should be "a media type or media type range". To be a valid media type the key would need to have a type then a / then a subtype.

In any case, Widdershins only knows how to represent schemas and examples if they are JSON, YAML, XML or text based. Other types such as image/* or application/pdf are not supported for the display of schemas or examples.

@KiperUladzislau
Copy link

@MikeRalphson Thanks for quick reply, by the way, do you plan to support other types such as application/* ?

@MikeRalphson
Copy link
Contributor

Unfortunately application/* covers such a wide range of media-types (e.g. application/octet-stream, application/pdf, application/zip, application/msword etc) that I don't immediately see a reasonable way to provide rendering for them. Open to suggestions though!

If your custom media-type value is based on JSON (which it might be, given your examples value) if you use application/whatever+json it should work as-is.

@achifal
Copy link
Author

achifal commented Jul 23, 2021

The custom MediaType is a placeholder.
For now when we have a custom media type, it appears in the resulting md file as
Accept: customMediaType
but response examples are not displayed. It seems that not showing examples of responses in the case of an unknown media type is a pretty tough 😃. How about representing examples with unknown media type as text/plain?

@MikeRalphson
Copy link
Contributor

@KirylBubovich would certainly look at an option to support this. Do you have any time to work up a PR?

@yuliya-ivaniukovich
Copy link

Hi @MikeRalphson, just created #462 with potential solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants