Skip to content

Commit

Permalink
Add CLI option to disable finding enums
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmior committed Aug 15, 2024
1 parent af3fe2d commit 43f25f6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add CLI option to disable finding enums

### Fixed
- Fix circular dependency with property sets
- Properly respect disjoint object detection in CLI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private final case class Config(
debug: Boolean = false,
detectDynamic: Boolean = false,
detectDisjoint: Boolean = false,
findEnums: Boolean = true,
numericStrings: Boolean = false
)

Expand Down Expand Up @@ -170,7 +171,8 @@ object DiscoverSchema {
otherSchema: Option[JsonSchema[_]] = None,
addDefinitions: Boolean = false,
detectDynamic: Boolean = false,
detectDisjoint: Boolean = false
detectDisjoint: Boolean = false,
findEnums: Boolean = true
)(implicit p: JsonoidParams): JsonSchema[_] = {
var transformedSchema = schema
if (detectDynamic) {
Expand All @@ -185,8 +187,10 @@ object DiscoverSchema {
transformedSchema = DefinitionTransformer
.transformSchema(transformedSchema)(p)
}
transformedSchema = EnumTransformer
.transformSchema(transformedSchema, otherSchema)(p)
if (findEnums) {
transformedSchema = EnumTransformer
.transformSchema(transformedSchema, otherSchema)(p)
}

// Reset max/min length from strings if a format is defined
if (p.resetFormatLength) {
Expand Down Expand Up @@ -314,6 +318,10 @@ object DiscoverSchema {
.action((x, c) => c.copy(detectDisjoint = true))
.text("detect objects with disjoint keys")

opt[Unit]("no-find-enums")
.action((x, c) => c.copy(findEnums = false))
.text("do not attempt to discover enumerations")

opt[Unit]("numeric-strings")
.action((x, c) => c.copy(numericStrings = true))
.text("detect numbers represented as strings")
Expand Down Expand Up @@ -494,7 +502,8 @@ object DiscoverSchema {
testSchema,
config.addDefinitions,
config.detectDynamic,
config.detectDisjoint
config.detectDisjoint,
config.findEnums
)(p)

// If debugging is enabled, save the schema before expansion
Expand Down

0 comments on commit 43f25f6

Please sign in to comment.