Skip to content

feat: add support for json:api content type #1187

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

gletournel
Copy link

@gletournel gletournel commented Apr 23, 2025

As stated by the JSON:API specification, all JSON:API requests MUST be sent using the JSON:API media type in the Content-Type header (application/vnd.api+json).

Solution proposal
Add a new JsonApi case to the ContentType enum for JSON:API media type.

export enum ContentType {
  Json = "application/json",
  JsonApi = "application/vnd.api+json",
  FormData = "multipart/form-data",
  UrlEncoded = "application/x-www-form-urlencoded",
  Text = "text/plain",
}

When OpenApi media type matches the JSON:API media type, don’t replace it with application/json.

getContentKind = (contentTypes) => {
  if (contentTypes.includes("application/vnd.api+json")) {
    return CONTENT_KIND.JSON_API;
  }

  if (
    contentTypes.some((contentType) =>
      contentType.startsWith("application/json"),
    ) ||
    contentTypes.some((contentType) => contentType.endsWith("+json"))
  ) {
    return CONTENT_KIND.JSON;
  }
  // ...
}

Closes #1188

Copy link

changeset-bot bot commented Apr 23, 2025

⚠️ No Changeset found

Latest commit: 0cc2966

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@gletournel gletournel force-pushed the feat/add-support-for-jsonapi-content-type branch from a32ed59 to d7ae545 Compare April 23, 2025 20:00
@smorimoto smorimoto requested a review from Copilot April 24, 2025 13:45
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for the JSON:API media type by introducing a new JSON_API case to the content kind mapping.

  • Introduces a JSON_API entry in the CONTENT_KIND constant.
  • Adds a conditional check in getContentKind to return JSON_API for the JSON:API media type.
Files not reviewed (19)
  • templates/base/http-clients/axios-http-client.ejs: Language not supported
  • templates/base/http-clients/fetch-http-client.ejs: Language not supported
  • templates/default/procedure-call.ejs: Language not supported
  • templates/modular/procedure-call.ejs: Language not supported
  • tests/snapshots/extended.test.ts.snap: Language not supported
  • tests/snapshots/simple.test.ts.snap: Language not supported
  • tests/spec/another-query-params/snapshots/basic.test.ts.snap: Language not supported
  • tests/spec/axios/snapshots/basic.test.ts.snap: Language not supported
  • tests/spec/axiosSingleHttpClient/snapshots/basic.test.ts.snap: Language not supported
  • tests/spec/custom-extensions/snapshots/basic.test.ts.snap: Language not supported
  • tests/spec/defaultAsSuccess/snapshots/basic.test.ts.snap: Language not supported
  • tests/spec/defaultResponse/snapshots/basic.test.ts.snap: Language not supported
  • tests/spec/deprecated/snapshots/basic.test.ts.snap: Language not supported
  • tests/spec/dot-path-params/snapshots/basic.test.ts.snap: Language not supported
  • tests/spec/enumNamesAsValues/snapshots/basic.test.ts.snap: Language not supported
  • tests/spec/enumNotFirstInComponents/snapshots/basic.test.ts.snap: Language not supported
  • tests/spec/extractRequestBody/snapshots/basic.test.ts.snap: Language not supported
  • tests/spec/extractRequestParams/snapshots/basic.test.ts.snap: Language not supported
  • tests/spec/extractResponseBody/snapshots/basic.test.ts.snap: Language not supported
Comments suppressed due to low confidence (1)

src/schema-routes/schema-routes.ts:284

  • Consider adding tests to validate the handling of the JSON:API content type in getContentKind.
if (contentTypes.includes("application/vnd.api+json")) {

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

Successfully merging this pull request may close these issues.

Add support for JSON:API media type
1 participant