StencilSwiftKit icon indicating copy to clipboard operation
StencilSwiftKit copied to clipboard

Create enum from multiple JSONs removing duplicated

Open BlanesP opened this issue 2 years ago • 1 comments

I have this simple custom template:

// swiftlint:disable all
// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen

{% if files %}
{% macro fileBlock file %}
  {% call documentBlock file.document %}
{% endmacro %}
{% macro documentBlock document %}
  {% for key,value in document.metadata.properties %}
  {% if key == "tests" %}
  {% for testKey,testValue in value.properties %}
    {%- set propertyName %}{{testKey|lowerFirstWord}}{% endset -%}
    case {{propertyName}} = "{{testKey}}"
  {% endfor %}
  {% endif %}
  {% endfor %}
{% endmacro %}
import Foundation

// MARK: - ABTest Names

enum ABTestNames: String {
{% for file in files %}
    {% call fileBlock file %}
{% endfor %}

}
{% endif %}

It reads from multiple JSON files and creates an enum with the keys of the elements in the "tests" property. The problem is that some of these keys are the same in different files and I want to remove the duplicated elements.

Is there a way to do that?

BlanesP avatar Jan 25 '24 17:01 BlanesP

I have this simple custom template:


// swiftlint:disable all

// Generated using SwiftGen — https://github.com/SwiftGen/SwiftGen



{% if files %}

{% macro fileBlock file %}

  {% call documentBlock file.document %}

{% endmacro %}

{% macro documentBlock document %}

  {% for key,value in document.metadata.properties %}

  {% if key == "tests" %}

  {% for testKey,testValue in value.properties %}

    {%- set propertyName %}{{testKey|lowerFirstWord}}{% endset -%}

    case {{propertyName}} = "{{testKey}}"

  {% endfor %}

  {% endif %}

  {% endfor %}

{% endmacro %}

import Foundation



// MARK: - ABTest Names



enum ABTestNames: String {

{% for file in files %}

    {% call fileBlock file %}

{% endfor %}



}

{% endif %}

It reads from multiple JSON files and creates an enum with the keys of the elements in the "tests" property.

The problem is that some of these keys are the same in different files and I want to remove the duplicated elements.

Is there a way to do that?

Ckrun12 avatar May 31 '24 03:05 Ckrun12