From 9124670c858075af0036d98cf40d68fc51951710 Mon Sep 17 00:00:00 2001 From: Simon Pilkington Date: Fri, 5 Aug 2022 06:26:11 +1000 Subject: [PATCH] Update README. --- .../SmokeFrameworkGenerateClient/plugin.swift | 10 ++---- .../SmokeFrameworkGenerateHttp1/plugin.swift | 10 ++---- .../SmokeFrameworkGenerateModel/plugin.swift | 10 ++---- README.md | 36 +++++++++++++++---- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/Plugins/SmokeFrameworkGenerateClient/plugin.swift b/Plugins/SmokeFrameworkGenerateClient/plugin.swift index 19fc34b..d079037 100644 --- a/Plugins/SmokeFrameworkGenerateClient/plugin.swift +++ b/Plugins/SmokeFrameworkGenerateClient/plugin.swift @@ -103,16 +103,10 @@ struct SmokeFrameworkGenerateClientPlugin: BuildToolPlugin { private func getModelFilePathOverride(target: Target, config: SmokeFrameworkCodeGen, baseFilePath: PackagePlugin.Path) throws -> String { // find the model for the current target - let filteredModelLocations = config.modelLocations?.targetMap.compactMap { (targetName, modelLocation) -> ModelLocation? in - if targetName == target.name { - return modelLocation - } - - return nil - } + let targetModelLocationOptional = config.modelLocations?.targetMap[target.name] let modelLocation: ModelLocation - if let theModelLocation = filteredModelLocations?.first { + if let theModelLocation = targetModelLocationOptional { modelLocation = theModelLocation } else if let theModelLocation = config.modelLocations?.default { modelLocation = theModelLocation diff --git a/Plugins/SmokeFrameworkGenerateHttp1/plugin.swift b/Plugins/SmokeFrameworkGenerateHttp1/plugin.swift index ed53fe0..63a209b 100644 --- a/Plugins/SmokeFrameworkGenerateHttp1/plugin.swift +++ b/Plugins/SmokeFrameworkGenerateHttp1/plugin.swift @@ -98,16 +98,10 @@ struct SmokeFrameworkGenerateHttp1Plugin: BuildToolPlugin { private func getModelFilePathOverride(target: Target, config: SmokeFrameworkCodeGen, baseFilePath: PackagePlugin.Path) throws -> String { // find the model for the current target - let filteredModelLocations = config.modelLocations?.targetMap.compactMap { (targetName, modelLocation) -> ModelLocation? in - if targetName == target.name { - return modelLocation - } - - return nil - } + let targetModelLocationOptional = config.modelLocations?.targetMap[target.name] let modelLocation: ModelLocation - if let theModelLocation = filteredModelLocations?.first { + if let theModelLocation = targetModelLocationOptional { modelLocation = theModelLocation } else if let theModelLocation = config.modelLocations?.default { modelLocation = theModelLocation diff --git a/Plugins/SmokeFrameworkGenerateModel/plugin.swift b/Plugins/SmokeFrameworkGenerateModel/plugin.swift index 6a46487..a53d5f7 100644 --- a/Plugins/SmokeFrameworkGenerateModel/plugin.swift +++ b/Plugins/SmokeFrameworkGenerateModel/plugin.swift @@ -99,16 +99,10 @@ struct SmokeFrameworkGenerateModelPlugin: BuildToolPlugin { private func getModelFilePathOverride(target: Target, config: SmokeFrameworkCodeGen, baseFilePath: PackagePlugin.Path) throws -> String { // find the model for the current target - let filteredModelLocations = config.modelLocations?.targetMap.compactMap { (targetName, modelLocation) -> ModelLocation? in - if targetName == target.name { - return modelLocation - } - - return nil - } + let targetModelLocationOptional = config.modelLocations?.targetMap[target.name] let modelLocation: ModelLocation - if let theModelLocation = filteredModelLocations?.first { + if let theModelLocation = targetModelLocationOptional { modelLocation = theModelLocation } else if let theModelLocation = config.modelLocations?.default { modelLocation = theModelLocation diff --git a/README.md b/README.md index dc14486..4a5b420 100644 --- a/README.md +++ b/README.md @@ -341,15 +341,39 @@ and then as a dependency of any targets you are using the SPM plugin for. ## Step 3: Update the code generation configuration file -Finally, in the `smoke-framework-codegen.json` configuration file, add the `modelProductDependency` field to specify where the model is located. +Finally, in the `smoke-framework-codegen.json` configuration file, add a `modelsLocation` block to specify where the model is +located, removing the `modelFilePath` field at the top level. ``` { - "baseName" : "EmptyService", - "modelProductDependency": "MyModelPackage", - "modelFilePath" : "Swagger.yaml", - "generationType" : "serverUpdateWithPlugin", - ... + "baseName" : "EmptyService", + "modelLocations": { + "default": { + "modelProductDependency": "MyModelPackage", + "modelFilePath" : "Swagger.yaml" + } + }, + ... +} +``` + +If you need to specify a separate model path for a particular target, you can also add this in the `modelsLocation` block. + +``` +{ + "baseName" : "EmptyService", + "modelLocations": { + "EmptyServiceExternalModel": { + "modelProductDependency": "MyModelPackage2", + "modelFilePath" : "Swagger.yaml" + } + "default": { + "modelProductDependency": "MyModelPackage", + "modelFilePath" : "Swagger.yaml" + } + }, + ... +} ``` By default, the name specified by the `modelProductDependency` field will be used for both the Product and the Target used by that Product