forked from asyncapi/modelina
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into fix_python_type_andinit
- Loading branch information
Showing
6 changed files
with
58 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,7 @@ | ||
import { | ||
ConstrainedMetaModel, | ||
ConstrainedEnumModel, | ||
ConstrainedMetaModelOptionsConst, | ||
ConstrainedReferenceModel, | ||
ConstrainedStringModel | ||
} from '../../../models'; | ||
import { PythonConstantConstraint } from '../PythonGenerator'; | ||
|
||
const getConstrainedEnumModelConstant = (args: { | ||
constrainedMetaModel: ConstrainedMetaModel; | ||
constrainedEnumModel: ConstrainedEnumModel; | ||
constOptions: ConstrainedMetaModelOptionsConst; | ||
}) => { | ||
const constrainedEnumValueModel = args.constrainedEnumModel.values.find( | ||
(value) => value.originalInput === args.constOptions.originalInput | ||
); | ||
|
||
if (constrainedEnumValueModel) { | ||
return `${args.constrainedMetaModel.type}.${constrainedEnumValueModel.key}`; | ||
} | ||
}; | ||
|
||
export function defaultConstantConstraints(): PythonConstantConstraint { | ||
return ({ constrainedMetaModel }) => { | ||
const constOptions = constrainedMetaModel.options.const; | ||
|
||
if (!constOptions) { | ||
return undefined; | ||
} | ||
|
||
if ( | ||
constrainedMetaModel instanceof ConstrainedReferenceModel && | ||
constrainedMetaModel.ref instanceof ConstrainedEnumModel | ||
) { | ||
return getConstrainedEnumModelConstant({ | ||
constrainedMetaModel, | ||
constrainedEnumModel: constrainedMetaModel.ref, | ||
constOptions | ||
}); | ||
} else if (constrainedMetaModel instanceof ConstrainedEnumModel) { | ||
return getConstrainedEnumModelConstant({ | ||
constrainedMetaModel, | ||
constrainedEnumModel: constrainedMetaModel, | ||
constOptions | ||
}); | ||
} else if (constrainedMetaModel instanceof ConstrainedStringModel) { | ||
return `"${constOptions.originalInput}"`; | ||
} | ||
|
||
return () => { | ||
return undefined; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters