{"action":"created","issue":{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/4226","repository_url":"https://api.github.com/repos/swagger-api/swagger-codegen","labels_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/4226/labels{/name}","comments_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/4226/comments","events_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/4226/events","html_url":"https://github.com/swagger-api/swagger-codegen/issues/4226","id":190589379,"number":4226,"title":"[java] discriminator not defined when inside an allOf: inline object","user":{"login":"jeff9finger","id":12804917,"avatar_url":"https://avatars.githubusercontent.com/u/12804917?v=3","gravatar_id":"","url":"https://api.github.com/users/jeff9finger","html_url":"https://github.com/jeff9finger","followers_url":"https://api.github.com/users/jeff9finger/followers","following_url":"https://api.github.com/users/jeff9finger/following{/other_user}","gists_url":"https://api.github.com/users/jeff9finger/gists{/gist_id}","starred_url":"https://api.github.com/users/jeff9finger/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeff9finger/subscriptions","organizations_url":"https://api.github.com/users/jeff9finger/orgs","repos_url":"https://api.github.com/users/jeff9finger/repos","events_url":"https://api.github.com/users/jeff9finger/events{/privacy}","received_events_url":"https://api.github.com/users/jeff9finger/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2016-11-20T22:40:14Z","updated_at":"2016-12-04T22:02:18Z","closed_at":null,"body":"##### Description\r\nWhen a discriminator is defined in a spec in an allOf inline object, it is ignored. This prevents the inheritance in the generated code from being generated correctly.\r\n\r\nI have been studying the open api spec and swagger-codegen projects for the constraints on allOf:\r\n\r\nIt appears that swagger-codegen (language is java) only recognizes the last inline element of an allOf: array. I have not found a statement in the open api spec or code in swagger-codegen that specifies this constraint.\r\n\r\n1. How are inline objects supposed to be handled when there are multiple inline objects defined within an allOf array?\r\n\r\n2. How are discriminators inside the objects from #1 supposed to be represented in the generated code (java in this case)?\r\n\r\nCurrently, it appears that only the last inline object is recognized.\r\n\r\nFYI: This came up in trying to define a discriminator for the inline object.\r\n\r\n##### Swagger-codegen version\r\n2.2.2-SNAPSHOT + pr 4085\r\n\r\n##### Swagger declaration file content or url\r\n```\r\ndefinitions:\r\n\r\n  Object:\r\n    allOf:\r\n      - $ref: '#/definitions/SomeOtherObject'\r\n      - type: object\r\n        discriminator: object_type0\r\n        required:\r\n          - object_type0\r\n        properties:          \r\n          object_type0:\r\n            type: string\r\n          name:\r\n            type: string\r\n      - type: object\r\n        discriminator: object_type1\r\n        required:\r\n          - object_type1\r\n        properties:          \r\n          object_type1:\r\n            type: string\r\n          name:\r\n            type: string\r\n```\r\n##### Command line used for generation\r\nMaven\r\n```\r\n                    <plugin>\r\n                        <groupId>io.swagger</groupId>\r\n                        <artifactId>swagger-codegen-maven-plugin</artifactId>\r\n                        <version>${swagger-codegen.version}</version>\r\n                        <executions>\r\n                            <execution>\r\n                                <id>xxx</id>\r\n                                <goals>\r\n                                    <goal>generate</goal>\r\n                                </goals>\r\n                                <phase>generate-test-sources</phase>\r\n                                <configuration>\r\n                                    <verbose>false</verbose>\r\n                                    <environmentVariables>\r\n                                    </environmentVariables>\r\n                                    <inputSpec>${project.build.directory}/${api.spec.file}</inputSpec>\r\n                                    <output>${project.build.directory}/generated/java-client</output>\r\n                                    <language>java</language>\r\n                                    <library>jersey2</library>\r\n                                    <configOptions>\r\n                                        <sourceFolder>.</sourceFolder>\r\n                                        <dateLibrary>java8</dateLibrary>\r\n                                        <hideGenerationTimestamp>false</hideGenerationTimestamp>\r\n                                    </configOptions>\r\n                                    <addCompileSourceRoot>true</addCompileSourceRoot>\r\n                                    <bigDecimalAsString>true</bigDecimalAsString>\r\n                                    <generateApiTests>true</generateApiTests>\r\n                                    <generateModelTests>true</generateModelTests>\r\n                                    <modelPackage>com.acme.api.model</modelPackage>\r\n                                    <apiPackage>com.acme.api</apiPackage>\r\n                                    <invokerPackage>com.acme.api.client</invokerPackage>\r\n                                </configuration>\r\n                            </execution>\r\n                        </executions>\r\n                    </plugin>\r\n```\r\n##### Related issues\r\nhttps://github.com/swagger-api/swagger-codegen/issues/2449\r\nhttps://github.com/swagger-api/swagger-codegen/pull/4085\r\nhttps://github.com/OAI/OpenAPI-Specification/issues/848\r\n\r\n##### Suggest a Fix\r\nAdding the following to DefaultCodeGen seems to fix the issue for me. However, this assumes that allOf: can have no more than one inline element that contains a discriminator. (My experience also shows that allOf: understands no more than one inline elements. If more than one exists, only last one is recognized).\r\n```\r\n@@ -1240,6 +1251,12 @@ public class DefaultCodegen {\r\n                 allProperties = new LinkedHashMap<String, Property>();\r\n                 allRequired = new ArrayList<String>();\r\n                 m.allVars = new ArrayList<CodegenProperty>();\r\n+                for (Model innerModel: composed.getAllOf()) {\r\n+                    if (innerModel instanceof ModelImpl) {\r\n+                        m.discriminator = ((ModelImpl) innerModel).getDiscriminator();\r\n+                        break; // only one discriminator allowed at the moment.\r\n+                    }\r\n+                }\r\n             } else {\r\n                 allProperties = null;\r\n                 allRequired = null;\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/comments/264735019","html_url":"https://github.com/swagger-api/swagger-codegen/issues/4226#issuecomment-264735019","issue_url":"https://api.github.com/repos/swagger-api/swagger-codegen/issues/4226","id":264735019,"user":{"login":"sreeshas","id":553879,"avatar_url":"https://avatars.githubusercontent.com/u/553879?v=3","gravatar_id":"","url":"https://api.github.com/users/sreeshas","html_url":"https://github.com/sreeshas","followers_url":"https://api.github.com/users/sreeshas/followers","following_url":"https://api.github.com/users/sreeshas/following{/other_user}","gists_url":"https://api.github.com/users/sreeshas/gists{/gist_id}","starred_url":"https://api.github.com/users/sreeshas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sreeshas/subscriptions","organizations_url":"https://api.github.com/users/sreeshas/orgs","repos_url":"https://api.github.com/users/sreeshas/repos","events_url":"https://api.github.com/users/sreeshas/events{/privacy}","received_events_url":"https://api.github.com/users/sreeshas/received_events","type":"User","site_admin":false},"created_at":"2016-12-04T22:02:18Z","updated_at":"2016-12-04T22:02:18Z","body":"> It is good to know that \"2 discriminators for Object which is forbidden.\" Where is that documented?\r\nIt is not explicit as mentioned by @cbornet but aren't discriminators by definition unique? If you have two discriminators for an Object, the server/client would have to look at two fields to decide the behavior.  \r\n\r\nI couldn't find the documentation. I believe the discussion here https://gist.github.com/leedm777/5730877 should be moved to wiki.\r\n\r\n>But also, please clarify what you mean by \"2 discriminators for Object\". Are you saying that having a discriminator in BaseObj and one in SubObj is forbidden?\r\n\r\nif it is not forbidden does it mean DailySubObj must be discriminated based on the context in which it is used?  i.e \r\nConsider two operations. Operation1  accepts BaseObj and Operation 2 accepts SubObj. \r\nIf DailySubObj is passed to Operation 1, the discriminator would be object_type. \r\nIf DailySubObj is passed to Operation 2, the discriminator would be sub_obj_type.\r\n\r\n\r\n@cbornet \r\n>>That's a good question. I think that it shouldn't be possible to have properties with the same name in a parent and a child (imagine one is string type and the other number). But the discriminator is kinda special...\r\n\r\nCan you explain what you meant when you said discriminator is kinda special? \r\n\r\n \r\n\r\n \r\n"}}
{"actor":{"display_login":"sreeshas"}}