From 43f25f62135b05ec3aefaaf16d288a73ab852f2a Mon Sep 17 00:00:00 2001 From: Michael Mior Date: Thu, 15 Aug 2024 13:04:20 -0400 Subject: [PATCH] Add CLI option to disable finding enums --- CHANGELOG.md | 3 +++ .../jsonoid/discovery/DiscoverSchema.scala | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40bf0711..13903ec1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/main/scala/io/github/dataunitylab/jsonoid/discovery/DiscoverSchema.scala b/src/main/scala/io/github/dataunitylab/jsonoid/discovery/DiscoverSchema.scala index dc058f44..d90106e9 100644 --- a/src/main/scala/io/github/dataunitylab/jsonoid/discovery/DiscoverSchema.scala +++ b/src/main/scala/io/github/dataunitylab/jsonoid/discovery/DiscoverSchema.scala @@ -40,6 +40,7 @@ private final case class Config( debug: Boolean = false, detectDynamic: Boolean = false, detectDisjoint: Boolean = false, + findEnums: Boolean = true, numericStrings: Boolean = false ) @@ -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) { @@ -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) { @@ -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") @@ -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