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

Merged

Conversation

gletournel
Copy link
Contributor

@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

🦋 Changeset detected

Latest commit: df005f7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
swagger-typescript-api Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another 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")) {

@gletournel gletournel force-pushed the feat/add-support-for-jsonapi-content-type branch from 0cc2966 to aff8c6c Compare May 15, 2025 12:47
@gletournel
Copy link
Contributor Author

Hi @smorimoto, I just realized I had forgotten to include a changeset in the PR. I’ve now added one following the bot’s guidelines. Feel free to review it and merge whenever it works best for you. Thanks again!

@smorimoto
Copy link
Collaborator

Thanks a lot!

smorimoto
smorimoto previously approved these changes May 15, 2025
Co-authored-by: Sora Morimoto <sora@morimoto.io>
@smorimoto smorimoto merged commit 1039ff1 into acacode:main May 15, 2025
1 check passed
@github-actions github-actions bot mentioned this pull request May 15, 2025
@gletournel gletournel deleted the feat/add-support-for-jsonapi-content-type branch May 19, 2025 08:10
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
2 participants