question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow mapping a media type to a schema definition

See original GitHub issue

This is a proposal for OpenAPI.next.


One of the foundations of REST are media types (inherited from MIME, such as text/html). A media type defines how a resource representation might look like, and what it means.

For JSON REST APIs described with Swagger, one possible way of using media types is to declare anything as application/json – because actually every message is in this format. But of course our API will not accept/produce just any JSON document – we have schema definitions which restrict what can be in a response, or in a body parameter, and whose descriptions also give some meaning to the fields of the JSON object. In effect, we are creating a kind of media type here.

In my team, we actually define a media type for each schema (e.g. application/x.zalando.wholesale.warehouse+json in one of my recent APIs), and use it also for the Content-Type and Accept headers (and document it in the produces/consumes properties of the operations).

Could we make it possible to formally name the media type belonging to a schema?

First, this is just documentation. But then this could also be used to enable Content-Negotiation (in #146), by linking it to the consumes/produces properties of an operation.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
DavidBiesackcommented, Apr 19, 2016

Most response objects are tied to a schema, so it seems natural to me to make the link between media type and schema at the schema object, not in the Response object. It is of no value to us to use the same schema but with different media types in different operations or responses. This of course assumes that the schema is sufficiently expressive enough to accurately describe the media type.

2reactions
DavidBiesackcommented, Apr 12, 2016

👍 the tools could also recognize the association (code gen, UI). For example, in the UI, select a Request Content Type from the drop down, and the UI would show the associated model schema, which the user could then select to populate the request body (or if there were an example associated with the schema or media type, populate the input text area with that example JSON.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL schema basics
Your GraphQL server uses a schema to describe the shape of your available data. This schema defines a hierarchy of types with fields...
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
The OpenAPI Specification defines a standard interface to RESTful APIs which allows both humans and computers to understand service capabilities without ...
Read more >
Schema and data type mapping in copy activity - Microsoft Learn
This article describes how the Azure Data Factory copy activity perform schema mapping and data type mapping from source data to sink data....
Read more >
Media Type Mapping in External Service ... - Salesforce Help
Specify a mapping from a dropdown menu on the registration screen, or provide the mapping with code by using Metadata API.
Read more >
Configuration schema/metadata - Drupal
The type mapping is a basic type for key-value pairs. By using the config_object type, the maintenance mode definition reuses the langcode and ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found