Comments (10)
I see. That intent wasn't fully clear - from a reading of the code.
I now see how current behavior is actually a better approach to
determining when additionalProperties should be included and when not.
It's a more natural extension of excess-property-checking in TypeScript.
Nicely done. Thanks much.
from ts-json-schema-generator.
@domoritz that's the workaround we are using today, yes we can continue using this workaround.
from ts-json-schema-generator.
I'd consider a pull request with tests if the changes to the library code are small (which I expect them to be).
from ts-json-schema-generator.
Usually, you wouldn't set it to true but define what types you expect additional properties to be. This is useful for mapsas in https://github.com/vega/typescript-to-json-schema/blob/master/test/valid-data/type-maps/schema.json#L38. Does this make sense?
from ts-json-schema-generator.
ah!
Two questions:
- Is there a way to specify this in the TypeScript definition? Ideally, @additionalProperties annotation on an object.
- Currently, this is being set to false. Which seems to trigger a
no additionalProperties allowed
check from a validator I am using. Per the spec, http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.10,additionalProperties
being absent is treated as empty schema, which should validate arbit additional props.
Basically, providing for 1 above will solve 2. Current behavior seems to be amiss from the standard.
Or did I miss something else again?! 😱
from ts-json-schema-generator.
- I haven't added anything but I don't see why we wouldn't be able to add it
- That seems to be the behavior you want from a json schema that is generated from typescript. https://github.com/YousefED/typescript-json-schema has an option to not automatically output
additionalProperties: false
but I haven't bothered adding this to this generator because I always want it.
I don't agree that what I'm doing is not a according to the standard. What this library does is try to create a correspondence between the behavior in typescript and the behavior in json schema. Can you give me an example where you would want a different behavior?
Note that you can a write in typescript (roughly, I don't have a compiler right now)
interface A {
foo: number
[key: string]: any
}
which will allow additional properties on the interface A.
from ts-json-schema-generator.
@domoritz we are using this great library but we found we need to allow customers sending JSON files with additional properties anywhere they want in JSON. Can I create a PR to add a --allowAdditionalProperties
flag? Thanks!
from ts-json-schema-generator.
@yliu-d would it make sense to just iterate over the generated JSON to change the property instead of adding support to the library itself?
from ts-json-schema-generator.
Would you accept a PR to add a flag for this?
My use case is that I'm writing a library that lets people check if their typescript types match up with a real piece of JSON (for example, the JSON you'd get back from an API call). The reason for it is so that people don't end up using operations in typescript on properties that may not exist in the actual JSON.
In this case, consumers don't care whether or not there are additional properties, they only care that the returned JSON has all of the properties that were specified in their type. https://github.com/tamj0rd2/ncdc
It seems like adding a flag may satisfy other people's use cases also. This is the only roadblock I'm facing switching from typescript-json-schema to this package
from ts-json-schema-generator.
Do you have any guidance on this? Should it be as easy as adding an allowAdditional flag to the different Object parser constructors? e.g InterfaceAndClassNodeParser and ObjectLiteralExpressionNodeParser
from ts-json-schema-generator.
Related Issues (20)
- constant number is converted to a generic `number` type HOT 4
- How to exclude underscore properties from json schema ? HOT 1
- Issues with generation of Union Type of Union Type on a Record HOT 1
- Argument of type 'Config' is not assignable to parameter of type 'CompletedConfig' in ts-json-schema-generator 2.0.0 HOT 2
- "foo" | "bar" | string; should not only map to a string HOT 9
- Improved Promise handling to support packages like Prisma HOT 1
- Literal and Record<never, never> crates empty object HOT 1
- Cannot migrate to version 2 due to typescript error type CompletedConfig HOT 2
- [Bug]: Error when using the binary (v2.1.0) HOT 9
- V2 creates empty definitions after updating from V1 HOT 5
- CLI usage is throwing an error with node 22 HOT 3
- RegExp types are now emitted, breaking schema validation (v2.1.1) HOT 1
- Error when following exports?
- Dist types now require @types/ts-expose-internals HOT 9
- Fix CJS imports HOT 8
- Invalid index in type HOT 10
- CLI - ENOENT: no such file or directory, open 'package.json' HOT 3
- Error: Unknown type "undefined" HOT 2
- Required types not allowed HOT 1
- Generator crashed when no package version is set HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-json-schema-generator.