Skip to content

[scala][http4s] fix escaping of reserved words for correct model dese… #21518

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 1 commit into
base: master
Choose a base branch
from

Conversation

donilg
Copy link
Contributor

@donilg donilg commented Jul 3, 2025

There is an example of correct openAPI specification:

{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API",
    "description": "A simple API with GET and POST endpoints",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.example.com/v1"
    }
  ],
  "paths": {
    "/users": {
      "get": {
        "summary": "Method that has models with a reserved word",
        "parameters": [
          {
            "name": "typeName",
            "in": "query",
            "description": "param",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "active",
                "inactive",
                "pending"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "User": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "active",
              "inactive",
              "pending"
            ]
          }
        },
        "required": [
          "type"
        ]
      }
    }
  }
}

JSON response is generated for this OpenAPI specification:

{"_type":"active"}

This is incorrect since we specified that the field should be named type, not _type.
I changed the escaping of reserved words to standard Scala backticks notation so that the JSON decoder could properly map the domain to JSON.

{"type":"active"}

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Hello! 👋
I'd love to get your eyes on this PR when you have a moment.
Thanks in advance!

@clasnake (2017/07), @shijinkui (2018/01), @ramzimaalej (2018/03), @chameleon82 (2020/03), @Bouillie (2020/04) @Fish86 (2023/06)

@donilg donilg force-pushed the scala-http4s-reserve-word-model branch from d3de2ae to de9ff5a Compare July 4, 2025 04:12
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.

1 participant