OpenAPITools / OpenAPITools/openapi-generator

[BUG] Supprt JsonLD, allow property names @id, @type and @context (specifically for typescript-fetch)

Open
#13,999 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Json-LD includes a few fields that starts with a @ sign, like @id, @type and ´@context, when using typescript-fetchthe@sign is stripped wich leads to invalid code (often duplicateid` properties).

I assumed modelPropertyNaming=original would work, but it had no effect.

openapi-generator version

npm: @openapitools/openapi-generator-cli 2.5.2

OpenAPI declaration file content or url
{
    "openapi": "3.0.0",
    "info": {
        "title": "Hello API Platform",
        "description": "",
        "version": "1.0.0"
    },
    "servers": [
        {
            "url": "/",
            "description": ""
        }
    ],
    "paths": {
        "/users/{id}": {
            "get": {
                "operationId": "api_users_id_get",
                "tags": [
                    "User"
                ],
                "responses": {
                    "200": {
                        "description": "User resource",
                        "content": {
                            "application/ld+json": {
                                "schema": {
                                    "$ref": "#/components/schemas/User.jsonld"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Resource not found"
                    }
                },
                "summary": "Retrieves a User resource.",
                "description": "Retrieves a User resource.",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "description": "User identifier",
                        "required": true,
                        "deprecated": false,
                        "allowEmptyValue": false,
                        "schema": {
                            "type": "string"
                        },
                        "style": "simple",
                        "explode": false,
                        "allowReserved": false
                    }
                ],
                "deprecated": false
            },
            "parameters": []
        }
    },
    "components": {
        "schemas": {
            "User.jsonld": {
                "type": "object",
                "description": "",
                "deprecated": false,
                "properties": {
                    "@context": {
                        "readOnly": true,
                        "oneOf": [
                            {
                                "type": "string"
                            },
                            {
                                "type": "object",
                                "properties": {
                                    "@vocab": {
                                        "type": "string"
                                    },
                                    "hydra": {
                                        "type": "string",
                                        "enum": [
                                            "http://www.w3.org/ns/hydra/core#"
                                        ]
                                    }
                                },
                                "required": [
                                    "@vocab",
                                    "hydra"
                                ],
                                "additionalProperties": true
                            }
                        ]
                    },
                    "@id": {
                        "readOnly": true,
                        "type": "string"
                    },
                    "@type": {
                        "readOnly": true,
                        "type": "string"
                    },
                    "id": {
                        "readOnly": true,
                        "type": "string",
                        "format": "ulid"
                    },
                    "name": {
                        "type": "string"
                    },
                    "email": {
                        "type": "string"
                    },
                    "roles": {
                        "readOnly": true,
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    },
                    "userIdentifier": {
                        "readOnly": true,
                        "type": "string"
                    }
                }
            }
        },
        "responses": {},
        "parameters": {},
        "examples": {},
        "requestBodies": {},
        "headers": {},
        "securitySchemes": {}
    },
    "security": [],
    "tags": []
}

Generation Details

I run this command as a php composer.json script:

        "generate-api": [
            "rm -Rf ../pwa/components/openapi",
            "bin/console api:openapi:export > openapi.json",
            "../pwa/node_modules/.bin/openapi-generator-cli generate -i openapi.json -o ../pwa/components/openapi -g typescript-fetch --additional-properties=supportsES6=true,npmVersion=6.9.0,typescriptThreePlus=true,allowUnicodeIdentifiers=true,disallowAdditionalPropertiesIfNotPresent=false,paramNaming=original,modelPropertyNaming=original,enumPropertyNaming=original,nullSafeAdditionalProps=true"
        ]
Steps to reproduce
// create openapi.json file
./node_modules/.bin/openapi-generator-cli generate -i openapi.json -o ./components/openapi -g typescript-fetch --additional-properties=supportsES6=true,npmVersion=6.9.0,typescriptThreePlus=true,allowUnicodeIdentifiers=true,disallowAdditionalPropertiesIfNotPresent=false,paramNaming=original,modelPropertyNaming=original,enumPropertyNaming=original,nullSafeAdditionalProps=true
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/5899

Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied openapi.json and run the documented openapi-generator-cli command using the typescript-fetch generator. Inspect the generated model output for the User.jsonld schema and trace how its @context, @id, and @type properties are named. Done means valid generated TypeScript preserves these properties without collisions with id.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.