swagger-api / swagger-api/swagger-codegen
[Javascript] Undeclared properties in the Object Model
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Properties not declared in Object type are ignored.
However, unless additionalProperties is specified, it should be incorporated.
definitions:
# It's a free form object accept any key/value.
myObject:
type: object
Generated Code snippet:
obj is always empty object {}.
exports.constructFromObject = function(data, obj) {
if (data) {
obj = obj || new exports();
}
return obj;
}
Swagger-codegen version
c91ce17aeeeae2982b4a648333835377adc8d054
Swagger declaration file content or url
swagger: '2.0'
info:
title: Test yaml
version: '1.0.0'
basePath: /api
schemes:
- https
- http
consumes:
- application/json
produces:
- application/json
paths:
'/books/{id}':
parameters:
- BookID:
name: id
in: path
description: Book ID
required: true
type: integer
format: int64
get:
operationID: GetBook
description: |
Get book
responses:
'200':
description: Succeeded.
schema:
$ref: '#/definitions/Book'
'404':
description: Not found.
schema:
type: object
put:
operationID: PutBook
description: |
Put book
parameters:
- name: PutBook
description: Book data.
in: body
required: true
schema:
$ref: '#/definitions/Book'
responses:
'200':
description: Succeeded.
schema:
type: object
definitions:
Book:
type: object
Command line used for generation
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i test.yml -l javascript -o js
Related issues/PRs
Similar to #4973
Suggest a fix/enhancement
If additionalProperties is not supplied, copy props in data to obj
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
Start with the JavaScript generator entry point that emits the shown constructFromObject function, then reproduce generation using the supplied Swagger YAML and command. Check the generated object for undeclared properties when additionalProperties is omitted. Done means free-form object data is retained while the existing behavior for declared properties remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100