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

Overriding Model #56

Closed
jeremyxxdman opened this issue Apr 8, 2014 · 11 comments
Closed

Overriding Model #56

jeremyxxdman opened this issue Apr 8, 2014 · 11 comments

Comments

@jeremyxxdman
Copy link

Is there any way can override model for swagger-maven-plugin ?

for example:

"Date": {
"id": "Date",
"properties": {
"time": {
"type": "long"
},
"minutes": {
"type": "int"
},
"seconds": {
"type": "int"
},
"hours": {
"type": "int"
....}

becomes

"Date": {
"id": "Date",
"properties": {
"value": {
"required": true,
"description": "Date in ISO-8601 format",
"notes": "Add any notes you like here",
"type": "string"
}
}
}

the original solution for override mode in swagger core seems not work for
swagger-maven-plugin (?)

any idea?

@michalig
Copy link

michalig commented Jul 8, 2014

Hi I've prepared a fix for that. Please check my branch:
https://github.com/michalig/swagger-maven-plugin

Now you can configure overridingModels in apiSource configuration:

<apiSource>
    ...
    <overridingModels>/swagger-overriding-models.json</overridingModels>
</apiSource>

Example swagger-overriding-models.json:

{
    "mapping" :
    {
        "className" : "org.joda.time.DateTime",
        "jsonString" : "{\"id\": \"Date\",\"properties\": {\"value\": {\"required\": true, \"description\": \"Date in ISO-8601 format\", \"notes\": \"Add any notes you like here\", \"type\": \"string\", \"format\": \"date-time\"}}}"
    }
}

kongchen added a commit that referenced this issue Jul 9, 2014
@kongchen
Copy link
Owner

Thanks for the patch!

@jianlans
Copy link

jianlans commented Nov 7, 2014

I have tried using the json override using the same swagger-overriding-models.json in sample project (just copied the file) but keep getting compiler error:

[ERROR] Failed to execute goal com.github.kongchen:swagger-maven-plugin:2.3.1:generate (default) on project swagger-maven-example: Swagger-overridingModels[/Users/jsong/dps-repo/swagger-maven-example/src/main/resources/swagger-overriding-models.json] must be a valid JSON file! No content to map due to end-of-input
[ERROR] at [Source: UNKNOWN; line: 1, column: 1]

Any suggestion what may be the problem?

@michalig
Copy link

michalig commented Nov 7, 2014

Can you please paste your swagger-overriding-models.json file?

@jianlans
Copy link

jianlans commented Nov 7, 2014

Here is the json file:

{
"mapping" :
{
"className" : "com.github.kongchen.swagger.sample.wordnik.model.Pet",
"jsonString" : "{"id": "MediaType","properties": {"value": {"required": true, "description": "Content-Type in HTTP request/response header", "notes": "Add any notes you like here", "type": "string", "format": "/"}}}"
}
}

Basically I copied the same json file from swagger-maven-plugin project and just changed class name.

@jianlans
Copy link

jianlans commented Nov 7, 2014

BTW, I also tried sample project https://github.com/kongchen/swagger-maven-example. After fixing the path in the pom.xml to point to the correct json file, I got the same error with no change to the source.

@michalig
Copy link

michalig commented Nov 7, 2014

Looks fine. Check if overridingModels path is set correctlly in pom.xml.

@jianlans
Copy link

jianlans commented Nov 7, 2014

for project https://github.com/kongchen/swagger-maven-example, I modified the path to:
${basedir}/src/main/resources/swagger-overriding-models.json

Is it correct?

@michalig
Copy link

michalig commented Nov 7, 2014

Try using just the "/swagger-overriding-models.json" part.

@jianlans
Copy link

jianlans commented Nov 7, 2014

Full setting for overridingModels element in pom.xml:
${basedir}/src/main/resources/swagger-overriding-models.json

@jianlans
Copy link

jianlans commented Nov 7, 2014

using "/swagger-overriding-models.json" does not seem to pick up the json. The output json does not contain the custom definition for Pet.

karmazyn pushed a commit to karmazyn/swagger-maven-plugin that referenced this issue May 22, 2015
karmazyn pushed a commit to karmazyn/swagger-maven-plugin that referenced this issue May 22, 2015
Added comments in README.md to introduce overridingModel feature.
karmazyn pushed a commit to karmazyn/swagger-maven-plugin that referenced this issue May 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants