Open tjboudreaux opened 7 years ago
@tjboudreaux thanks for reporting the issue. Is PhoneNumber
defined as a property in a model?
Btw, stable version 2.2.0 has been released. Please give it a try as it contains a lot of enhancements.
@wing328, yes it's defined as a property on multiple models. Here's one example:
OrderRestaurant:
type: object
required:
- id
- name
- address
- phone_number
properties:
id:
type: string
name:
type: string
address:
$ref: '#/definitions/Address'
phone_number:
$ref: '#/definitions/PhoneNumber'
We also tried the stable version and that did not solve this specific issue.
Swagger parser does not support that at the moment: https://github.com/swagger-api/swagger-parser/issues/243
As a workaround, please define the primitive type inline instead of using $ref
Is any checkin done to fix this? Looking to see if I can use master SNAPSHOT for this
A note here if and when fix is provided. If you inline primitive type and build the contract, jackson serializes it differently than having an Object property. Swagger Codegen currently generates a Java model class for primitive json(although no property is present).
Same problem when I tried to generate Swift code with references to definition with primitive type.
Hi all, please try the latest master (with new swagger parser), which has better support for reference to primitive type.
If there's still an issue, we'll reopen this issue.
Tried this with the latest master and swagger-parser 1.028 that fixes https://github.com/swagger-api/swagger-parser/issues/243 but this issue is not resolved.
This also seems to affect the Python client generator.
However, it seems to be fixed in the latest version of the Python client generator.
@jimvmathews did you do a mvn clean package
to rebuild the JAR after pulling the latest master?
It seems to be still not fixed in the java codegen on http://editor2.swagger.io/
Please build the JAR based on the latest master of Swagger Codegen and see if the issue still persists.
I mean the one that this site uses: http://editor2.swagger.io/ The admin of that site has to update it. Who is the admin?
I just pulled and rebuilt (mvn clean package), then used swagger-codegen-cli to regenerate my java. While the useless model class doesn't exist, the code still uses it as if it did (including an import!)
Maybe I need to do something to make sure swagger-parser is up to date? I have no idea how that's getting pulled in or anything.
@theindexer can you please provide a spec to reproduce the issue?
I have just run into this issue.
swagger: '2.0'
info:
version: 1.0.0
title: Number API
host: localhost
basePath: /v2
schemes:
- http
paths:
'/numbers':
get:
summary: Get an array of numbers
description: Returns an array of numbers
operationId: getNumbers
produces:
- application/json
responses:
'200':
description: successful operation
schema:
$ref: '#/definitions/Numbers'
definitions:
Numbers:
type: array
items:
$ref: '#/definitions/Number'
Number:
type: number
This will generate a Numbers class, which extends ArrayList
@dentych what about defining the array of model response the following way instead?
Looks like I'm still getting this issue in v2.3.0-SNAPSHOT (built from the latest master) although the Java object that is incorrectly created also doesn't exist!
swagger: '2.0'
info:
description: >-
This is a sample server Petstore server. You can find out more about
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
#swagger](http://swagger.io/irc/). For this sample, you can use the api
key `special-key` to test the authorization filters.
version: 1.0.0
title: Swagger Petstore
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: petstore.swagger.io
basePath: /v2
schemes:
- http
paths:
/pet:
get:
summary: Return a random pet
operationId: randomPet
consumes:
- application/json
produces:
- application/json
responses:
'200':
description: A pet is returned
schema:
$ref: '#/definitions/PetResponse'
definitions:
PetResponse:
type: object
properties:
datetime:
type: string
format: datetime
example: '2017-01-01T00:00:00Z'
pet:
$ref: '#/definitions/Pet'
Pet:
type: object
properties:
name:
$ref: '#/definitions/PetName'
PetName:
type: string
description: A pet`s name
example: Mr Snuggle-Bunny
public class Pet {
@JsonProperty("name")
private PetName name = null;
public Pet name(PetName name) {
this.name = name;
return this;
}
/**
* Get name
* @return name
**/
@ApiModelProperty(value = "")
@Valid
public PetName getName() {
return name;
}
The class mentioned Petname
hasn't been created either! Same thing happens with v2.2.3. I'd expect the Pet
class to have a name
property of type String
.
opened this issue on 29 Jul 2016 - any news?
Description
In our definitions file, we have some definitions that are done for specifying constraints on primitives. Below is an example of an
integer
definition that we use for a Phone Number.When doing code generation for a Java client library, this definition gets generated as a model, but there is no way to get or set it's value.
Swagger-codegen version
2.1.6
Swagger declaration file content or url
This is the generated code for this definition: https://gist.github.com/tjboudreaux/4263e3329e2239557155e0f87f6a8b0c
Command line used for generation
swagger-codegen generate -i api/swagger/swagger.json -l java -o builds/android -c
Steps to reproduce
Related issues
No related issues.
Suggest a Fix
I believe the issue is that if a definition is a primitive, it should either: