Skip to content

Emit types instead of classes for JavaScript #287

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- [JavaScript] BREAKING CHANGE: Emit types instead of classes ([#287](https://github.com/cucumber/messages/pull/287))

### Fixed
- [python] Add a LICENSE file for Python ([#278](https://github.com/cucumber/messages/pull/278))
Expand Down
12 changes: 2 additions & 10 deletions codegen/templates/typescript.ts.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { Type } from 'class-transformer'
import 'reflect-metadata'

<% @schemas.each do |key, schema| -%>
export class <%= class_name(key) -%> {
export type <%= class_name(key) -%> = {
<%- schema['properties'].each do |property_name, property| -%>

<%- ref = property['$ref'] || property['items'] && property['items']['$ref'] -%>
<%- if ref -%>
<%- %> @Type(() => <%= class_name(ref) -%>)
<%- end -%>
<%- if (schema['required'] || []).index(property_name) -%>
<%- %> <%= property_name %>: <%= type_for(class_name(key), property_name, property) -%> = <%= default_value(class_name(key), property_name, property) -%>
<%- %> <%= property_name %>: <%= type_for(class_name(key), property_name, property) -%>
<%- else -%>
<%- %> <%= property_name %>?: <%= type_for(class_name(key), property_name, property) -%>
<%- end -%>
Expand Down
30 changes: 5 additions & 25 deletions javascript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@
"prepublishOnly": "npm run build && npm run copy-schemas"
},
"dependencies": {
"@types/uuid": "10.0.0",
"class-transformer": "0.5.1",
"reflect-metadata": "0.2.2",
"uuid": "11.0.5"
},
"devDependencies": {
"@types/mocha": "10.0.10",
"@types/node": "22.13.1",
"@types/uuid": "10.0.0",
"copyfiles": "2.4.1",
"mocha": "11.1.0",
"shx": "^0.3.4",
Expand Down
Loading
Loading