Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Protein fails to generate proper code when objects have dots in their name #29

Open
MichalDanielDobrzanski opened this issue Jan 17, 2019 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@MichalDanielDobrzanski
Copy link

MichalDanielDobrzanski commented Jan 17, 2019

Describe the bug
Protein is a really cool tool, I like it! However, it has failed to generate right names for data classes.
Generated classes are like "data class Class.V1.API.Model", and their names are put in Kotlin captions ``.

To Reproduce
Just add dots in the object names in JSON file.
Example:

  "Company.MyAwesomeApi.Contracts.V1.Specific.SecondSpecific": {
            "type": "object",
            "properties": {
                "date": {
                    "format": "date-time",
                    "type": "string"
                },
                "extendedPropertyTypeId": {
                    "format": "uuid",
                    "type": "string"
                },
                "value": {
                    "type": "string"
                }
            }
        },

Expected behavior
The easiest way would be to trim dots and generate clients with CapitalCase naming convenetion (or camelCase):
CompanyMyAwesomeApiContractsV1SpecificSecondSpecific
The JSON file cannot be changed since it is generated via .NET code and they use dots for namespaces.

Info Required

  • Which version of the plugin do you actually use?
    The latest one - 1.1.2

  • Any other thing that could help me to reproduce the error?

Screenshots

Additional context

@ferranpons ferranpons added the bug Something isn't working label Jan 21, 2019
@ferranpons ferranpons self-assigned this Jan 21, 2019
@ferranpons
Copy link
Member

Hi @MichalDanielDobrzanski

I'm checking the problem you describe but I'm not sure if it's a generator problem or a definition problem. I explain, if the definition must be the final name of the class why you define it with dots instead of using the correct naming instead?
If that swagger definition is auto-generated from the .NET backend service may it be corrected there IMHO. You want me to make a change to fit your needs when you should change how you name those objects.
Is more like "linting" the JSON than changing the tool.

We can debate it if you're not agree.

@yudhir
Copy link

yudhir commented Apr 7, 2019

"\/api\/sections\/{id}": {
			"get": {
				"tags": [
					"Section"
				],
				"operationId": "getSectionItem",
				"produces": [
					"application\/ld+json",
					"application\/json",
					"text\/html",
					"application\/hal+json",
					"multipart\/form-data"
				],
				"summary": "Retrieves a Section resource.",
				"parameters": [{
					"name": "id",
					"in": "path",
					"required": true,
					"type": "string"
				}],
				"responses": {
					"200": {
						"description": "Section resource response",
						"schema": {
							"$ref": "#\/definitions\/Section-section.read"
						}
					},
					"404": {
						"description": "Resource not found"
					}
				}
			},

here is a snippet.

@ApiModel
final class Section-section.read { Error expecting top level declaration, 

  @ApiModelProperty
  @SerializedName("name")          Error Functio declaration must have a name
  private var name: String```



@delete("/api/sections/{id}")
fun deleteSectionItem(): Observable<Article-section.read> Expecting Member declaration

@ferranpons
Copy link
Member

Hi @yudhir !

Why you named a reference that way? Since a reference should be a model from your definition, is there any reason for that?

Please could you post the definition of Section-section.read?
Is auto-generated from an external service?

Thanks!

@yudhir
Copy link

yudhir commented Apr 10, 2019

yes it was autogenerated from api-platform and probably a result of intenal Joins and Serialization and Normalization rules. here is my swagger

 "Section-section.read": {
            "type": "object",
            "description": "The most generic type of item.",
            "properties": {
                "name": {
                    "description": "the name of the item",
                    "type": "string"
                },
                "image": {
                    "description": "An image of the item. This can be a \\[\\[URL\\]\\] or a fully described \\[\\[ImageObject\\]\\].",
                    "type": "string"
                },
                "description": {
                    "description": "a description of the item",
                    "type": "string"
                },
                "articles": {
                    "type": "array",
                    "items": {
                        "$ref": "#\/definitions\/Article-section.read"
                    }
                },
                "newsArticles": {
                    "type": "array",
                    "items": {
                        "$ref": "#\/definitions\/NewsArticle-section.read"
                    }
                }
            }
        },

OpenaApi gen i think used SectionMinusSectionRead to get around this . I need an Rx, Retrofit solution , that is not available on the openapi-gen and swagger-gen .

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

No branches or pull requests

3 participants