serverless / typescript

TypeScript definitions for Serverless Framework service configuration
141 stars 25 forks source link

org: and app: missing from serverless schema? #32

Closed markcastle closed 3 years ago

markcastle commented 3 years ago

Hi, New here :-)

I'm trying to migrate existing microservices to typescript using your awesome work but when I try to migrate the following...

org: COMPANY
app: APPNAME
service: SERVICENAME

eg,

const serverlessConfiguration: AWS = {
  org: 'COMPANY',
  app: 'APPNAME',
  service: 'SERVICENAME',
  frameworkVersion: '2',

I get...

"Object literal may only specify known properties, and 'org' does not exist in type 'AWS'.ts(2322)"

Understandably this doesn't exist as from what I can see you are generating types directly from the schema at https://github.com/serverless/serverless/blob/master/lib/configSchema.js which doesn't include them..

I'm a bit confused as to how I can migrate my microservices to ts with these elements though (and more confused why serverless requires them for compatibility with their dashboard but they don't appear to exist in the validation schema.

...I'm guessing I've missed something somewhere? I'm rather new to typescript, please forgive my ignorance on this.

the workaround I'm currently using is...

const serverlessConfiguration: AWS & {org: string, app: string} = {
  org: 'COMPANY',
  app: 'APPNAME',
  service: 'SERVICENAME',
  frameworkVersion: '2',

...but this seems a bit wrong to be doing this.

markcastle commented 3 years ago

I guess these params are newer than I thought with some updates to their recognition in serverless 2.27.0

https://github.com/serverless/serverless/pull/8997

fredericbarthelet commented 3 years ago

Hi @markcastle, thanks for submitting your issue :)

org and app params are not defined within Serverless core framework. They are part of the enterprise plugin. Plugins can alter the schema used for validation using dedicated API described in https://www.serverless.com/framework/docs/providers/aws/guide/plugins#extending-validation-schema.

This API is actually used in enterprise plugin code base to add those properties : https://github.com/serverless/enterprise-plugin/blob/836a0fa0e8e54f3a389ce418b57b5dbe0e90f75f/lib/plugin.js#L60-L69

While this repository is not generating definitions for any plugin, the core framework comes pre-bundled with a dependency to the enterprise plugin. Those parameter should have been enclosed within the generated definition.

Taking a closer look, I realized that the schema used for building definition is the one existing at plugin instance creation (since a clone of the schema is done in plugin constructor). Moving the retrieval of the schema in the command execution block actually now takes schema modifications made by other plugin into account :) PR #34 fixes this issue !

Thanks for your feedback, next version of typescript definition will hold those missing properties. I'm closing in the meantime, feel free to re-open in case you're facing any additional issue