Reputation: 535
Some help needed i was trying to generate the swagger client code using the command for an Expedia mobile API
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i https://www.expedia.co.jp/static/mobile/swaggerui/swagger.json -l java -o samples/client/expedia
The code generation fails with the following error
[main] ERROR io.swagger.codegen.languages.JavaClientCodegen - No Type defined for Property null Exception in thread "main" java.lang.RuntimeException: Could not generate model 'detailedRentalFare'
The type attribute within the DetailedRentalFare is where it fails. I am not sure why this fails since the data type is defined. I am newbie to Swagger any help will be greatly appreciated
Upvotes: 0
Views: 11557
Reputation: 6824
From @wing328's answer, even if this isn't your service to fix, you can still generate a client from it.
First, just download the JSON locally:
wget https://www.expedia.co.jp/static/mobile/swaggerui/swagger.json > expedia.json
Next, modify the value in the JSON that @wing328 pointed out
Finally, rerun your codegen using the static file as the source:
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-i ./expedia.json \
-l java \
-o samples/client/expedia
It's always nice to let the service owner know about the issue, too, since fixing it will help with their adoption of the api.
Upvotes: 1
Reputation: 535
Answer provided by @wing328
the issue is caused by incorrect type for array, e.g.
"detailedRentalFare": {
"properties": {
"rateTerm": {
"type": "string",
"description": "It can have the following values: HOURLY, DAILY, WEEKLY, WEEKEND, MONTHLY, TOTAL, TRIP"
},
"rate": {
"$ref": "mobilePrice"
},
"priceBreakdownOfTotalDueToday": {
"type": "array",
"items": {
"type": "rentalFareBreakdownItem"
}
},
It should be
"items": {
"$ref": "rentalFareBreakdownItem"
}
or even better
"items": {
"type": "object",
"$ref": "rentalFareBreakdownItem"
}
After correcting this i was able to generate the code.
Upvotes: 0