Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create enum from multiple JSONs removing duplicated #177

Open
BlanesP opened this issue Jan 25, 2024 · 1 comment
Open

Create enum from multiple JSONs removing duplicated #177

BlanesP opened this issue Jan 25, 2024 · 1 comment

Comments

@BlanesP
Copy link

BlanesP commented Jan 25, 2024

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
Copy link

Ckrun12 commented May 31, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants