OpenAPITools / OpenAPITools/openapi-generator
[BUG] typescript generator fails to generate for string of format URI
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Any models with properties of format: uri generate with a missing URI.ts file.
foo:
type: string
format: uri
Output from compilation. No templates were found for URI when extracting to customize by using author option on jar.
$ npm install
> prepare
> npm run build
> build
> tsc
models/CreatePostRequest.ts(13,21): error TS2307: Cannot find module './URI' or its corresponding type declarations.
models/Post.ts(13,21): error TS2307: Cannot find module './URI' or its corresponding type declarations.
models/UpdatePostRequest.ts(14,21): error TS2307: Cannot find module './URI' or its corresponding type declarations.
openapi-generator version
5.1.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: optimistic.ninja API
version: v1
servers:
- description: Local
url: http://localhost:8080/v1
- description: Production
url: https://api.optimistic.ninja/v1
paths:
/auth/register:
post:
description: Register user
operationId: registerUser
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/RegisterUserRequest'
description: Register user request
required: true
responses:
"201":
description: Created user
headers:
Location:
description: The location of the created user's identity page.
example: "/v1/users/0000000-0000-0000-000-000000000000"
explode: false
schema:
format: uri
type: string
style: simple
"400":
description: Bad request
tags:
- auth
x-contentType: application/json
x-accepts: application/json
/auth/login:
put:
description: Login user
operationId: loginUser
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/LoginUserRequest'
description: Login user request
required: true
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/LoginUserResponse'
description: User logged in
"401":
description: Unauthorized
tags:
- auth
x-contentType: application/json
x-accepts: application/json
/users:
get:
security:
- bearerAuth: []
description: Get paged users
operationId: getUsers
parameters:
- description: page offset
explode: true
in: query
name: page
required: false
schema:
format: int64
type: integer
style: form
- description: page size
explode: true
in: query
name: size
required: false
schema:
format: int64
type: integer
style: form
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/ListUsersResponse'
description: A paged list of users
tags:
- users
x-accepts: application/json
/users/{userId}:
get:
security:
- bearerAuth: [ ]
description: Get user
operationId: getUser
parameters:
- explode: false
in: path
name: userId
required: true
schema:
format: uuid
type: string
style: simple
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/User'
description: A user
tags:
- users
x-accepts: application/json
/posts:
get:
description: Get paged posts
operationId: getPosts
parameters:
- description: page offset
explode: true
in: query
name: page
required: false
schema:
format: int64
type: integer
style: form
- description: page size
explode: true
in: query
name: size
required: false
schema:
format: int64
type: integer
style: form
- description: query
explode: true
in: query
name: query
required: false
schema:
type: string
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/ListPostsResponse'
description: A paged list of posts
tags:
- posts
x-accepts: application/json
post:
security:
- bearerAuth: [ ]
description: Create a post
operationId: createPost
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CreatePostRequest'
description: Create post request
required: true
responses:
"201":
description: Created post
headers:
Location:
description: The location of the created post.
explode: false
schema:
format: uri
type: string
style: simple
"400":
description: Bad request
"401":
description: Unauthorized
"403":
description: Forbidden
tags:
- posts
x-contentType: application/json
x-accepts: application/json
/posts/{postId}:
delete:
security:
- bearerAuth: [ ]
description: Delete a post
operationId: deletePost
parameters:
- explode: false
in: path
name: postId
required: true
schema:
format: uuid
type: string
style: simple
responses:
"204":
description: No content
"401":
description: Unauthorized
"403":
description: Forbidden
"404":
description: Post not found
tags:
- posts
x-accepts: application/json
get:
description: Get a post
operationId: getPost
parameters:
- explode: false
in: path
name: postId
required: true
schema:
format: uuid
type: string
style: simple
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/Post'
description: A post
"404":
description: Post not found
tags:
- posts
x-accepts: application/json
patch:
security:
- bearerAuth: [ ]
description: Update a post
operationId: updatePost
parameters:
- explode: false
in: path
name: postId
required: true
schema:
format: uuid
type: string
style: simple
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UpdatePostRequest'
description: Update post request
required: true
responses:
"204":
description: No content
"400":
description: Bad request
"401":
description: Unauthorized
"403":
description: Forbidden
"404":
description: Post not found
tags:
- posts
x-contentType: application/json
x-accepts: application/json
/posts/{postId}/comments:
parameters:
- description: postId
explode: false
in: path
name: postId
required: true
schema:
format: uuid
type: string
style: simple
get:
description: Get paged comments
operationId: getComments
parameters:
- description: page offset
explode: true
in: query
name: page
required: false
schema:
format: int64
type: integer
style: form
- description: page size
explode: true
in: query
name: size
required: false
schema:
format: int64
type: integer
style: form
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/ListCommentsResponse'
description: A paged list of comments
tags:
- comments
x-accepts: application/json
post:
security:
- bearerAuth: [ ]
description: Create a comment
operationId: createComment
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/CreatePostCommentRequest'
description: Create post request
required: true
responses:
"201":
description: Created comment
headers:
Location:
description: The location of the created comment.
explode: false
schema:
format: uri
type: string
style: simple
"400":
description: Bad request
"401":
description: Unauthorized
"403":
description: Forbidden
tags:
- comments
x-contentType: application/json
x-accepts: application/json
/posts/{postId}/comments/{commentId}:
parameters:
- explode: false
in: path
name: postId
required: true
schema:
format: uuid
type: string
style: simple
delete:
security:
- bearerAuth: [ ]
description: Delete a comment
operationId: deleteComment
parameters:
- explode: false
in: path
name: commentId
required: true
schema:
format: uuid
type: string
style: simple
responses:
"204":
description: No content
"401":
description: Unauthorized
"403":
description: Forbidden
"404":
description: Post not found
tags:
- comments
x-accepts: application/json
get:
description: Get a comment
operationId: getComment
parameters:
- explode: false
in: path
name: commentId
required: true
schema:
format: uuid
type: string
style: simple
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/Comment'
description: A comment
"404":
description: Comment not found
tags:
- comments
x-accepts: application/json
patch:
security:
- bearerAuth: [ ]
description: Update a comment
operationId: updateComment
parameters:
- explode: false
in: path
name: commentId
required: true
schema:
format: uuid
type: string
style: simple
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateCommentRequest'
description: Update comment request
required: true
responses:
"204":
description: No content
"400":
description: Bad request
"401":
description: Unauthorized
"403":
description: Forbidden
"404":
description: Post not found
tags:
- comments
x-contentType: application/json
x-accepts: application/json
components:
schemas:
RegisterUserRequest:
example:
password: password
email: email
properties:
email:
description: registration email
format: email
type: string
password:
description: registration password
type: string
maxLength: 72
displayName:
description: display name
type: string
required:
- email
- username
- password
LoginUserRequest:
example:
password: password
email: email
properties:
email:
description: login email
format: email
type: string
password:
description: login description
type: string
maxLength: 72
required:
- email
- password
LoginUserResponse:
example:
accessToken:
tokenType: Bearer
properties:
accessToken:
description: JSON web token
type: string
tokenType:
description: Authorization header value prefix
type: string
required:
- jwt
- tokenType
User:
example:
created: 2000-01-23T04:56:07.000+00:00
id: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
updated: 2000-01-23T04:56:07.000+00:00
email: email
properties:
id:
description: user id
format: uuid
type: string
email:
description: user email
format: email
type: string
displayName:
description: display name
type: string
created:
description: date-time of user creation
format: date-time
type: string
updated:
description: date-time of post last modified
format: date-time
type: string
ListUsersResponse:
example:
nextPage: 1
users:
- created: 2000-01-23T04:56:07.000+00:00
id: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
updated: 2000-01-23T04:56:07.000+00:00
email: email
- created: 2000-01-23T04:56:07.000+00:00
id: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
updated: 2000-01-23T04:56:07.000+00:00
email: email
properties:
users:
description: list of users
items:
$ref: '#/components/schemas/User'
type: array
nextPage:
description: next page of users
format: int64
type: integer
pageCount:
description: number of pages
format: int64
type: integer
required:
- users
- pageCount
PostUpdateMask:
description: "update mask for post, empty updates all"
enum:
- MARKDOWN
- TITLE
- SUMMARY
- IMAGE_URL
type: string
Post:
example:
summary: summary
created: 2000-01-23T04:56:07.000+00:00
imageUrl: https://openapi-generator.tech
markdown: markdown
id: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
authorId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
title: title
updated: 2000-01-23T04:56:07.000+00:00
properties:
id:
description: post ID
format: uuid
type: string
authorId:
description: post author's ID
format: uuid
type: string
created:
description: date-time of post creation
format: date-time
type: string
updated:
description: date-time of post last modified
format: date-time
type: string
title:
description: post title
maxLength: 140
minLength: 1
type: string
summary:
description: post summary
maxLength: 280
minLength: 1
type: string
markdown:
description: post markdown
type: string
imageUrl:
description: post banner/card image url
format: uri
maxLength: 2083
minLength: 8
type: string
required:
- authorId
- markdown
- summary
- title
type: object
ListPostsResponse:
example:
nextPage: 1
posts:
- summary: summary
created: 2000-01-23T04:56:07.000+00:00
imageUrl: https://openapi-generator.tech
markdown: markdown
id: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
authorId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
title: title
updated: 2000-01-23T04:56:07.000+00:00
- summary: summary
created: 2000-01-23T04:56:07.000+00:00
imageUrl: https://openapi-generator.tech
markdown: markdown
id: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
authorId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
title: title
updated: 2000-01-23T04:56:07.000+00:00
properties:
posts:
description: list of posts
items:
$ref: '#/components/schemas/Post'
type: array
nextPage:
description: next page of posts
format: int64
type: integer
pageCount:
description: number of pages
format: int64
type: integer
required:
- posts
- pageCount
CreatePostRequest:
example:
summary: summary
imageUrl: https://openapi-generator.tech
markdown: markdown
title: title
properties:
title:
description: created post title
maxLength: 50
minLength: 3
type: string
markdown:
description: created post markdown
type: string
imageUrl:
description: created post banner/card image url
type: string
format: uri
summary:
description: created post description
maxLength: 255
minLength: 3
type: string
required:
- markdown
- summary
- title
UpdatePostRequest:
example:
summary: summary
imageUrl: https://openapi-generator.tech
markdown: markdown
title: title
updateMask:
- SUMMARY
- IMAGE_URL
- MARKDOWN
- TITLE
properties:
title:
description: new post title
maxLength: 50
minLength: 3
type: string
summary:
description: new post description
maxLength: 255
minLength: 3
type: string
markdown:
description: new post markdown
type: string
imageUrl:
description: new post banner/card image url
type: string
format: uri
updateMask:
items:
$ref: '#/components/schemas/PostUpdateMask'
type: array
ListCommentsResponse:
example:
comments:
- created: 2000-01-23T04:56:07.000+00:00
markdown: markdown
id: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
postId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
authorId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
updated: 2000-01-23T04:56:07.000+00:00
parentId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
- created: 2000-01-23T04:56:07.000+00:00
markdown: markdown
id: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
postId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
authorId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
updated: 2000-01-23T04:56:07.000+00:00
parentId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
nextPage: 1
properties:
comments:
description: list of comments
items:
$ref: '#/components/schemas/Comment'
type: array
nextPage:
description: next page of comments
format: int64
type: integer
pageCount:
description: number of pages
format: int64
type: integer
required:
- comments
- pageCount
CommentUpdateMask:
description: "update mask for post, empty updates all"
enum:
- MARKDOWN
type: string
Comment:
example:
created: 2000-01-23T04:56:07.000+00:00
markdown: markdown
id: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
postId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
authorId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
updated: 2000-01-23T04:56:07.000+00:00
parentId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
properties:
id:
description: comment id
format: uuid
type: string
created:
description: date-time of user creation
format: date-time
type: string
updated:
description: date-time of post last modified
format: date-time
type: string
authorId:
description: author id
format: uuid
type: string
parentId:
description: parent comment id
format: uuid
type: string
postId:
description: post id
format: uuid
type: string
markdown:
description: comment markdown
type: string
required:
- authorId
- created
- id
- markdown
- postId
- updated
CreatePostCommentRequest:
example:
markdown: markdown
postId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
parentId: 046b6c7f-0b8a-43b9-b35d-6489e6daee91
properties:
parentId:
description: parent comment id
format: uuid
type: string
markdown:
description: comment markdown
type: string
required:
- markdown
- postId
UpdateCommentRequest:
example:
markdown: markdown
updateMask:
- MARKDOWN
properties:
markdown:
type: string
updateMask:
items:
$ref: '#/components/schemas/CommentUpdateMask'
type: array
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
Generation Details
Using Gradle generator version 5.1.0 with Java 11.
Steps to reproduce
Generate any model with a
property:
type: string
format: uri
Related issues/PRs
None that I found
Suggest a fix
Will dive into templates and latest master release on a less busy day.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with the supplied OpenAPI schema, then run npm install and npm run build to inspect the generated models and the missing URI.ts import. Trace the TypeScript generator's handling of string properties with format: uri. Done means the generated output includes the required URI type and the TypeScript build completes without TS2307 errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100