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

Model interface not generated in version 2.0 typescript-angular for nested properties #304

Closed
topce opened this issue Jun 13, 2018 · 8 comments

Comments

@topce
Copy link
Contributor

topce commented Jun 13, 2018

Description

Model interface not generated in version 2.0 typescript-angular for nested properties

openapi-generator version

3.0.1 master

it is regression if we compare with swagger-codegen master

OpenAPI declaration file content or url
swagger: '2.0'
info:
  title: Test
  description: Test
  version: "1.0.0"
host: "localhost:8002"
schemes:
  - http
basePath: /v1
produces:
  - application/json
securityDefinitions:
  basicAuth:
    type: basic
    description: HTTP Basic Authentication
security:
  - basicAuth: []
paths:

definitions:
  NotificationDefinition:
    type: object
    description: the representation of all the notification configuration of one node
    properties:
      profiles:
        type: array
        items:
          type: object
          properties:
            profile:
              $ref: "#/definitions/Profile"
            notifications:
              type: string
            inherited:
              type: boolean
      users:
        type: array
        items:
          type: object
          properties:
            user:
              $ref: "#/definitions/User"
            notifications:
              type: string
            inherited:
              type: boolean
  User:
    type: object
    description: a CIRCABC user
    properties:
      userId:
        type: string
      firstname:
        type: string
      lastname:
        type: string
      email:
        type: string
      phone:
        type: string
      uiLang:
        type: string
      contentFilterLang:
        type: string
      visibility:
        type: boolean
      properties:
        type: object
        description: |
          properties field will receive all the configuration parameters relative
          to the user accound. For example notification / prefered language / etc.
      avatar:
        type: string
        description: |
          Used to get the URL of the user picture that will be shown everywhere in the app
  Profile:
    type: object
    description: the representation of an access profile definition inside an Interest Group
    properties:
      id:
        type: string
      name:
        type: string
      title:
        $ref: string
      groupName:
        type: string
      permissions:
        type: object
        additionalProperties:
          type: string
      imported:
        type: boolean
      importedRef:
        type: string
        description: |
          in the case the profile is imported from another group, it is the IG nodeRef from which
          it has been imported
      exported:
        type: boolean
      exportedRefs:
        type: array
        items:
          type: string
        description: |
          in the case the profile is exported and imported at least once in an IG, it is the list of
          all the IGs in which the profile has been imported into

it generates

export interface NotificationDefinition { 
    profiles?: Array<any>;
    users?: Array<any>;
}

before it generated 3 files

/// fist 
import { NotificationDefinitionProfiles } from './notificationDefinitionProfiles';
import { NotificationDefinitionUsers } from './notificationDefinitionUsers';

export interface NotificationDefinition { 
    profiles?: Array<NotificationDefinitionProfiles>;
    users?: Array<NotificationDefinitionUsers>;
}
//// second 
import { Profile } from './profile';


export interface NotificationDefinitionProfiles { 
    profile?: Profile;
    notifications?: string;
    inherited?: boolean;
}
/// third

import { User } from './user';


export interface NotificationDefinitionUsers { 
    user?: User;
    notifications?: string;
    inherited?: boolean;
}
Command line used for generation

org.openapitools.codegen.OpenAPIGenerator
generate -i C:\swagger.yaml -g typescript-angular -o C:\temp --additional-properties ngVersion=6.0.0

Steps to reproduce

run generator with provided yaml file typescript-angular

Related issues/PRs

probably same issue is presented with some other generators

Suggest a fix/enhancement
@topce
Copy link
Contributor Author

topce commented Jun 25, 2018

@jmini @wing328
any news on this one ?

@topce
Copy link
Contributor Author

topce commented Jul 10, 2018

@wing328
@TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny
any news on this one it still broken and it is blocking issue

@macjohnny
Copy link
Member

@wing328 @jmini I can confirm this still is an issue with 3.1.0 for typescript-angular and spring, so I think this is an issue with the default codegen / parser.
could be related to #222 and #8

@topce would you like to attempt to fix this? maybe @wing328 @jmini can point you to the starting point

@macjohnny
Copy link
Member

macjohnny commented Jul 10, 2018

@topce the problem can be fixed by changing the api definition as follows:

swagger: '2.0'
info:
  title: Test
  description: Test
  version: "1.0.0"
host: "localhost:8002"
schemes:
  - http
basePath: /v1
produces:
  - application/json
securityDefinitions:
  basicAuth:
    type: basic
    description: HTTP Basic Authentication
security:
  - basicAuth: []
paths:

definitions:
  NotificationDefinition:
    type: object
    description: the representation of all the notification configuration of one node
    properties:
      profiles:
        type: array
        items:
          $ref: "#/definitions/ProfileWrapper"
      users:
        type: array
        items:
          $ref: "#/definitions/UserWrapper"
  User:
    type: object
    description: a CIRCABC user
    properties:
      userId:
        type: string
      firstname:
        type: string
      lastname:
        type: string
      email:
        type: string
      phone:
        type: string
      uiLang:
        type: string
      contentFilterLang:
        type: string
      visibility:
        type: boolean
      properties:
        $ref: '#/definitions/Properties'
      avatar:
        type: string
        description: |
          Used to get the URL of the user picture that will be shown everywhere in the app
  Profile:
    type: object
    description: the representation of an access profile definition inside an Interest Group
    properties:
      id:
        type: string
      name:
        type: string
      title:
        $ref: string
      groupName:
        type: string
      permissions:
        $ref: '#/definitions/Permissions'
      imported:
        type: boolean
      importedRef:
        type: string
        description: |
          in the case the profile is imported from another group, it is the IG nodeRef from which
          it has been imported
      exported:
        type: boolean
      exportedRefs:
        type: array
        items:
          type: string
        description: |
          in the case the profile is exported and imported at least once in an IG, it is the list of
          all the IGs in which the profile has been imported into

  ProfileWrapper:
    type: object
    properties:
      profile:
        $ref: "#/definitions/Profile"
      notifications:
        type: string
      inherited:
        type: boolean
  UserWrapper:
    type: object
    properties:
      user:
        $ref: "#/definitions/User"
      notifications:
        type: string
      inherited:
        type: boolean
  Properties:
    type: object
    description: |
      properties field will receive all the configuration parameters relative
      to the user accound. For example notification / prefered language / etc.
  Permissions:
    type: object
    additionalProperties:
      type: string

I successfully tested the above spec with typescript-angular and OpenAPI Generator 3.1.0
the reason is that inline-defined objects are not generated, see #222 (comment)

@jmini I think this issue should be closed as a duplicate of #8

@topce
Copy link
Contributor Author

topce commented Jul 10, 2018

Thank you @macjohnny for fast comment and workaround.
@jmini probably you are right I will close this on
even this one is little bit different it use swagger: '2.0'
not openapi: 3.0.0

@jmini and @wing328 do you think we should fix this
or you recommend me to change swagger.yaml file as workaround ?

@topce topce closed this as completed Jul 11, 2018
@macjohnny
Copy link
Member

macjohnny commented Jul 17, 2018

@topce

do you think we should fix this

I think #8 should definitely be fixed. meanwhile, the workaround is not hacky, so you can use it without any issue.

@topce
Copy link
Contributor Author

topce commented Jul 17, 2018

Thank you @macjohnny !
Workaround works for me as well ;-)

@jmini
Copy link
Member

jmini commented Aug 16, 2018

There was some work made with #736 for version 3.2.1 can you give this version a try?
(#736 is a start, maybe more use cases needs to be covered as discuss in #8)

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

3 participants