![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
json2jsii
Advanced tools
Generates jsii-compatible structs from JSON schemas
const g = new TypeGenerator({
definitions: {
Name: {
description: 'Represents a name of a person',
required: [ 'firstName', 'lastName' ],
properties: {
firstName: {
type: 'string',
description: 'The first name of the person',
},
lastName: {
type: 'string',
description: 'The last name of the person',
},
},
},
},
});
// definitions can also be added like this:
g.addDefinition('Person', {
required: [ 'name' ],
properties: {
name: {
description: 'The person\'s name',
$ref: '#/definitions/Name',
},
color: {
description: 'Favorite color. Default is green',
enum: [ 'red', 'green', 'blue', 'yellow' ],
},
},
});
// this will emit the specified type & recursively all the referenced types.
g.emitType('Person');
fs.writeFileSync('gen/ts/person.ts', await g.render());
Then, gen/ts/person.ts
will look like this;
/**
* @schema Person
*/
export interface Person {
/**
* The person's name
*
* @schema Person#name
*/
readonly name: Name;
/**
* Favorite color. Default is green
*
* @default green
* @schema Person#color
*/
readonly color?: any;
}
/**
* Represents a name of a person
*
* @schema Name
*/
export interface Name {
/**
* The first name of the person
*
* @schema Name#firstName
*/
readonly firstName: string;
/**
* The last name of the person
*
* @schema Name#lastName
*/
readonly lastName: string;
}
It is possible to offer an alias to a type definition using addAlias(from, to)
. The type generator will resolve any references to the original type with
the alias:
const gen = new TypeGenerator();
gen.addDefinition('TypeA', { type: 'object', properties: { ref: { $ref: '#/definitions/TypeB' } } } );
gen.addDefinition('TypeC', { type: 'object', properties: { field: { type: 'string' } } });
gen.addAlias('TypeB', 'TypeC');
gen.emitType('TypeA');
This will output:
interface TypeA {
readonly ref: TypeC;
}
interface TypeC {
readonly field: string;
}
Once you generate jsii-compatible TypeScript source (such as person.ts
above),
you can use jsii-srcmak in order to
produce source code in any of the jsii supported languages.
The following command will produce Python sources for the Person
types:
$ jsii-srcmak gen/ts \
--python-outdir gen/py --python-module-name person \
--java-outdir gen/java --java-package person
See the jsii-srcmak for library usage.
All contributions are celebrated.
Distributed under the Apache 2.0 license.
FAQs
Generates jsii structs from JSON schemas
We found that json2jsii demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.