Skip to content
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

Error when generating classes with FedEx OpenAPI schema #72

Open
mehgcap opened this issue May 16, 2023 · 4 comments · May be fixed by #74
Open

Error when generating classes with FedEx OpenAPI schema #72

mehgcap opened this issue May 16, 2023 · 4 comments · May be fixed by #74
Assignees
Labels
bug Something isn't working

Comments

@mehgcap
Copy link

mehgcap commented May 16, 2023

Describe the bug
When I use this library to try to generate PHP classes from FedEx's OpenAPI schema for their new RESTful API, I get this error:

PHP Fatal error: Uncaught PHPModelGenerator\Exception\SchemaException: No nested schema for composed property RequestePackageLineItemDimensions in file /[...]/utils/../schemas/rate.json

(Note: that should be RequestedPackageLineItemDimensions, but the first 'd' is missing in the reference and the definition, so it shouldn't matter.)

This is mentioned in issue 57, but the solution there was to alter the schema. Since the goal is to be as hands-off as possible, I'd much prefer to simply download the schemas and run this function on them. I don't want to have to modify every schema we need (ship, rate, address validation, and more) each time we have to update to a new API release. I've installed a java-based tool that converts schemas into PHP, and it didn't encounter this problem when using this schema, so I know it's possible. I also validated the schema with two online validators, and both indicated that the JSON is valid for OpenAPI.

Expected behavior

Given that this is a valid OpenAPI 3 schema from a major company, I expect it to be processed into PHP classes properly.

Schema

https://developer.fedex.com/api/en-us/catalog/rate/v1/docs.html > click "download JSON schema". I'd link to it directly here, but the page uses some JS to actually serve the JSON file.

Here's the function I'm using to try to generate the classes:

function generate() {
	$generator = new ModelGenerator(
		(new GeneratorConfiguration())
		->setNamespacePrefix('models\fedex')
		->setSerialization(true)
		->setCollectErrors(false)
		->setImmutable(false)
	);
	$schemaPath = dirname(__FILE__) . '/../schemas/rate.json';
	$resultDirectory = dirname(__FILE__) . '/../models/fedex';
	$generator
		->generateModelDirectory($resultDirectory)
		->generateModels(new OpenAPIv3Provider($schemaPath), $resultDirectory);
}

Version:

0.23.3

Additional context

I don't think I have anything to add. I'm experienced with PHP, but very new to OpenAPI and class generation. If more information is required, please ask.

@wol-soft
Copy link
Owner

wol-soft commented May 23, 2023

Hi, thanks for the report. I've figured out the issue with the RequestedPackageLineItemDimensions which is related to nested usage of allOf compositions which work with a patch I've developed (still need to write some test cases).

Another issue which occurs later is related to the Body entry of the schema, a large collection of oneOf references where only a single oneOf branch provides an actual schema. All other branches provide example data (so strictly no validation rules and every body is valid as a oneOf branch with only example data is always fulfilled no matter which data is provided). I'll have a deeper look into it and check if it makes sense to skip branches which only contain example data during the generation process.

For example:

{
  "body": 34
}

validates against the following simplified schema which shows the issue with the Body from the rate.json schema which doesn't seem to be intended:

{
  "type":"object",
  "properties":{
  	"body": {
    	"oneOf": [
          {
            "type":"object",
            "properties": {
              "name": {
              	"type": "string"
              }
            },
            "required": ["name"]
          },
          {
            "example": {
              "name": "wol-soft"
            }
          }
        ]
    }
  },
  "required": ["body"]
}

@wol-soft wol-soft added the bug Something isn't working label May 23, 2023
@wol-soft wol-soft self-assigned this May 23, 2023
@mehgcap
Copy link
Author

mehgcap commented May 23, 2023

Thank you for checking into this! It would be great if your library could support these schemas. Everything I've tried so far has either choked on them, or generated output we've had to manually modify afterward. I think the body section you mentioned was a problem, and was one thing we had to remove from classes generated with another tool.

@wol-soft wol-soft linked a pull request May 30, 2023 that will close this issue
@Kindlewing
Copy link

Kindlewing commented Jun 1, 2023

I pulled issue72_nestedCompositionbranch that links to this issue, and used it to generate ship models from FedEx's ship schema and got this error:

Message: Unresolved Reference #/components/schemas/RequestedShipment in file /tmp/ship.json    in file: /home/hfinn/repos/ship/vendor/wol-soft/php-json-schema-model-generator/src/PropertyProcessor/Property/ReferenceProcessor.php  
 on line: 50
    

Same as the rate schema, go to Shipping documentation > click Download Json Schema to look at the json.

@wol-soft
Copy link
Owner

wol-soft commented Jun 7, 2023

Hi, I'm still facing some issues with the rate.json related to validators in combination with the nested allOf usage.

It takes some time to further investigate the issue which I'm currently not able to invest - sorry. I'll check it, when time allows.
To be fair: this seems to be the most complex schema I've seen the library being used on. Nice challenge 😄

Then I'll also have a look at the shipping schema. The schema looks correct, the reference is defined and consequently should be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants