swagger-api / swagger-api/swagger-codegen-generators
[BUG][PHP] hydra model properties with @ prefix are removed which can result in method duplicates and invalid classes
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
Description
When generating PHP client classes from a schema generated by API Platform you can get invalid PHP classes because of clashing method names. A Hydra model can have "@id" and "id" as properties resulting in two clashing getId methods
generator version
3.0.35-SNAPSHOT
3.0.34
OpenAPI declaration file content or url
Book.jsonld-book.read:
type: object
description: ''
externalDocs:
url: 'https://schema.org/Book'
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: uuid
nullable: true
Steps to reproduce
wget https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.34/swagger-codegen-cli-3.0.34.jar -O swagger-codegen-cli.jarwget https://gist.githubusercontent.com/warmwaterkruik/d6836d463ef765c8ae16a0ff53f68d3f/raw/f3cc01c42a87b79d101a2326d12142ff8a362260/bookshop-api.yamljava -jar swagger-codegen-cli.jar generate --lang php --input-spec bookshop-api.yaml --output ${PWD}- Check the generated file BookJsonld.php - This is invalid because of double getId() methods
Suggest a fix
Pull request opened with fix: https://github.com/swagger-api/swagger-codegen-generators/pull/1042
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided Hydra schema and reproduce the issue using swagger-codegen-cli.jar with the PHP generator. Inspect the generated BookJsonld.php and the generator path responsible for handling @-prefixed properties. Done means the schema no longer produces duplicate getId() methods or an invalid PHP class; a pull request is already linked in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 20/100