Skip to content

Commit

Permalink
Update README.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Pilkington committed Aug 4, 2022
1 parent 7e50fc5 commit 9124670
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
10 changes: 2 additions & 8 deletions Plugins/SmokeFrameworkGenerateClient/plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions Plugins/SmokeFrameworkGenerateHttp1/plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions Plugins/SmokeFrameworkGenerateModel/plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9124670

Please sign in to comment.